Harsh Chelyabinsk 1C developers and how to use XSLT
I was puzzled by the question - what are “template engines” and what's the point?
It is useful to read, but everything is somehow about the "boars for sipuleniya in sipulyarii." But for half a day, in general, I began to realize what some people have, speaking about the separation of logic from presentation and the benefit of template engines for large projects, where you do not need to pull the coder in order to fix something somewhere, they say - “designer this is work. ”
All the complexity of perception of this topic arises only due to the fact that there is a real template engine - for example, XML -> XLST -> “Hello world!” And many others, which in fact are libraries of the language extension. What do I want to say with this? Yes, the fact that Smarty, for example, is not a template engine, but only a library of acronyms that allows you to write (I do not know PHP or Smarty, this is just an attempt to explain on the fingers, do not bother with the code) {foreach from=$data item="entry"} {$entry.Comment|escape}
Those. there is no separation of logic and mapping - we simply use the language extension . We must be aware of exactly which variables and in what form (what type) we are returning from the main code, after which we use these variables in the template engine for display. ')
Serialization of data does not occur, but only serialization allows you to guarantee the "purity" of data from the logic of the source. I'm not talking about the fact that the serialized data can not contain any code, I say that it ceases to be executable. The addressee of the data must independently decide how exactly the data received by him will be restored, the “sentence” should contain at a minimum both the subject and predicate in order to be able to independently restore the essence of what was said. The data contained does not "imply" anything else or is not silent about something, they are exactly what they are.
Well, for example, if you take the expression - "This loaf costs 5 rubles!" For serialized, then the options for non-implemented expressions will be like this - "It costs 5 rubles! (What?) "," A bun costs 5 rubles (What?) "," This bun costs 5 (What?) "," This bun costs 5 rubles! (Local currency is bread?) "And the apotheosis will be" It costs money (???) "and" See the price list! (wtf ?!) ”.
Smarty allows the developer to say something like "-This bun costs 5 rubles, because we are a pathetic boutique on Tverskaya!" and a decision should be made on the basis of the data obtained from it and being within the limits of its logic. That is, to begin to think "- A, etozh Tverskaya, immediately everything is expensive, it means that bablos is slobbering as they said".
Serialization allows one to step back from the logic of the source and it is quite reasonable to assume “- Expensive!”, Correlating the heard cost with his idea of what bread should cost, after which he politely inquired whether the fish soup was tasted here to offer the seller to go light on an erotic foot journey.
Serialization is a pack of printed photos from the last trip that you brought with you to show your grandmother in the village. Non-serialized data - when instead of 13x15 photographs printed on matte paper, you are taking a Blu-ray disc with you, finding it obvious that there is a Blu-ray-capable laptop somewhere there.
Well, we were inspired by the idea that “serialization” is a blessing, but what’s 1C?
Well, they seem to have enlightened this idea, at least Mr. Ryzhikov, who created the unforgettable verse of the Illusions of XML / XSLT technologies . I personally vaguely imagine how much and what needs to be smoked so that “I myself am a programmer” who has read
There are many books and textbooks in which programmers and designers were taught that the best way to create a templating system or to abstract the appearance (presentation) of data is to drive everything into XML, then skip it through XSLT and get HTML at the output.
put a taboo on the back-end logic and
Everyone took it literally and started making similar products. And of course, we also heard and believed that our future is XML / XSLT technologies. They accomplished the feat by forcing XSLT templates to work fast enough, they invested a lot of effort, time and money in developing the technology ... The largest catalogs of products contained 70 thousand products.
concluded that:
As developers do not try, the performance of XML / XSLT systems remains very low, despite the best efforts of the industry. Yes, and how to squeeze this performance? First, the data from the SQL database is converted to XML (and this is a large text file due to its structure). Then the XML data is loaded into the XML parser already in the server part, where they take up even more memory for XPATH operation, generating indexes on the XML data at the time of loading, etc. Next, XSLT goes through a huge array of data, receiving again the text that takes up memory.
At the same time, he didn’t sincerely understand what was going on when he was asked the question - “Where do huge amounts of data come from, if the content per page is 100 kilos maximum ???”.
Indeed, how not to take a huge amount, if you handle the xml-dump base XSL-template?
Madness of the brave we sing a song!
No less fun to read "independent developers" who agree with the master - "XSLT - brakes and sucks!".
No, well, imagine for yourself - it is exactly (in the sense absolutely equivalent) how to stumble on a topic in LJ
-Today, he took up the bare wires, standing in a wet bath. Nekhilo shocked me with a current, I came to myself for 3 hours!
with a crowd of comments:
- And today I took the wires! And I fucked!
- +1 bath sucks! Rubber mats they rule!
- Rubber - sucks, better plastic!
- You yourself suck, and your plastic - fufel!
- I answered for the bazaar that plastic is a fufel?
- Ha, yes, I have a friend - the director of a tire factory, they only use rubber there, and not some kind of plastic shit. No need to explain to you how cool it is to make tires! This is not some kind of candle factory in Uryupinsk, the same production!
- And so every time I am shocked with electricity, when I take the wires, it suffers!
- Yes, you loshara, here I once banged in the bath from the wires, so I fucked them knocked out in the shield in the basement! That neither me, not my family, nor neighbors beat! We must also think about others!
Clinic, in one word :)
Please do not do this!
The template should do exactly what it does - take it off the shelf and complete the product with accessories, depending on whether it is OEM or Retail. If Retail - then put the disk, and loops and manuals in all languages, and keychain. And if OEM - sneeze in the package for the kit to the piece of hardware itself. At the same time, the order picker works with a specific piece of hardware and with some finite amount of accessories suitable for this device. He is not trying to stuff the power supply box into the box with the video card, because it has an additional connector - the power supply unit is not included in the package according to its TI, or instead of putting a bottle of brandy instead of throwing it into the store, because it is for "himself." And, all the more, they don’t say to him: “Here’s vidyuha, here’s a warehouse of sets — choose something-thread and put it there, you're a small man!”
The separation of logic means it, logic, separation - no more and no less! (if you shudder from such wording - just ignore, and if some vague guess flashed in the brain - re-read to enlightenment)
You still have a SQL database with a fucking cloud of records (as befits a decent SQL database); a back-end that goes to the database and receives about a dozen entries from it (in accordance with the user's request and the paging display logic that instructs to display 15 entries, and the title should not have the word “Ass” if the user has “ to 18 ") at the exit wrapping up the results of their work in XML; The front-end receives a short XML and superimposes its own style sheet, aka XLST, resulting in a new XML file, in which the original <bullshit> Suit and Tie - $ 5000 </ bullshit> node changes to <Haute couture> Suit and Tie - $ 5,000 </ Haute couture>.
And where is the HTML? Yes, here it is, darling, just in another template - toHTML, for the <bullshit> node there is another rule that transforms it into <span class = "amazing">, which is given to the client by the same front-end if the user cannot read XML. Yes, the essence of the front-end-namely, to speak with the client in one language, while he does not care about what they are talking about - clothes or booze. He and about that and about that can, if the prompter-back-end prompts what to insert after "This is a very cool thing, ours" ...
In short, if you were able to finish this and are still trying to implement the back-end as an XLST transformation of the XML-dump of the database - it’s a direct way to you in 1C, to do Bitrix-s under the guidance of Mr. Ryzhikov. Or not, they will not take you for the words XML and XSLT, they are already “stuck” on it and will not “fool” any more. Well, then re-read this opus once more or try to write an angry response to it, thinking about each phrase.
UP. Disclaimer - the complexity of the text, its confusion, the isolation of examples from the subject and tede - the result of the extremely superficial knowledge of the author in the subject under discussion. At the moment, all my XLST training consists of reading the first sentence of the XLST, a standard that says:
It defines the syntax of the XSLT, which is a language for transforming XML.