Open capocasa opened 4 years ago
SCF is IMO a perfect example of a mis-feature that un-necessarily complicates the language (edge cases etc, complex feature interaction), and is best replaced by standard nim code (strformat + friends) with more flexibility, no worse readibility. Standard separation of concerns. I'd like for it to be deprecated (even if with a long deprecation cycle).
But please prove me wrong with a SCF example where the nim equivalent is inferior.
I understand that stuff like SPF can complicate development through edge cases, however it is also extremely useful. I know of two ways you can get string templating this good using language features: Nim SPFs, and PHP (PHP can be nasty but it does a couple of things really well). And it's the only way of getting string templating this good into an executable.
SPF goes really well with strformat enabling crazy powerful hacks. Also the last time this was discussed strformat couldn't have loops and branches.
The number of special cases like this one are finite. I understand that maybe there shouldn't be two dozens more features like this one, but let's keep this one!
Edit: @timotheecour To directly answer your question:
#? stdtmpl(emit="stdout.write")
# import os
# if paramCount() == 0:
Oh you did not add an argument. Try foo, bar, fuz or buz.
# else:
# case paramStr(1):
# of "foo":
Oh look you wrote foo.
# of "bar":
Oh look you wrote bar
# of "fuz":
Oh look you wrote fuz
# of "buz":
Man I'm glad I don't have to write echo
in front of every one of these conditions
# for i in 0..5:
especially when I have complex nested stuff like this
# end for
implicit echo is positively liberating.
# end case
# end if
Ever seen a textual interactive program this concise?
But please prove me wrong with a SCF example where the nim equivalent is inferior.
To directly answer your question:
Can you please come up with a more convincing example, that example does nothing but confirm what I said above.
end for|case|if
, different file extension, ? stdtmpl(emit="stdout.write")
)
=> that's a tell-tell sign of a misfeatureI don't see any benefit in implicit echo
; if you have some boilerplate, use a template or macro.
Ever seen a textual interactive program this concise?
yes, the nim version is more concise / readable and correctly syntax highlighted + indented:
import os
if paramCount() == 0: echo "Oh you did not add an argument. Try foo, bar, fuz or buz."
else:
case paramStr(1):
of "foo": echo "Oh look you wrote foo."
of "bar": echo "Oh look you wrote bar"
of "fuz": echo "Oh look you wrote fuz"
of "buz": echo """Man I'm glad I don't have to write echo
in front of every one of these conditions"""
for i in 0..5:
echo "especially when I have complex nested stuff like this"
echo "implicit echo is positively liberating."
Source code filters are ignored when nim code is compiled via stdin rather than from a file.
Example
Current Output
Expected Output
Possible Solution
Apply calls to scfs in stdinfile.nim
Additional Information