News for hackers. Stuff that matters.
Re:Ropes, an Alternative to Strings [pdf] (1995) by chrisseaton on Sunday November 01, 2020 @12:23PM (#24960938)
> I guess what I'm saying is that if you "properly" write a template engine, there should be no advantage to ropes at all.

If you're building up your string as an array of strings, and you want to pass that to some existing code that expects a full string (like the web framework you're using) then you're going to need to flatten it to create the final full string.

Ropes don't need to do that. They still have an advantage.

Also... the implementation doing things for you so you don't have to manually optimise your code is kind of the point of an optimisation. We can always say 'but I could do this manually' to any optimisation, couldn't we?

Re:Ropes, an Alternative to Strings [pdf] (1995) by chubot on Sunday November 01, 2020 @12:56PM (#24961177)
Yeah it's a moot point either way, because ERB is like that... but

- This wasn't an optimization, it was literally the first thing I thought of when I wrote my first and only template engine 10 years ago. And I have seen plenty of others do it; it is "obvious".

The code is the exact same length as the string version, so I don't consider it an optimization.

- Python's WSGI accepts an iterable of strings for the body. From a cursory reading, looks like Ruby's rack does too:

https://en.wikipedia.org/wiki/Rack_(web_server_interface)#Ex...

e.g. it's ["Hello, World"] and not "Hello, World" (I don't know Ruby that well though)

Maybe frameworks mess it up in the middle...