4 ms·
"Code is meant to be consumed by machines" Well, partly. Code is actually a piece of writing intended for two very different audiences - one human, one machin
by jayferd 13y ago
"Code is meant to be consumed by machines"
Well, partly. Code is actually a piece of writing intended for two very different audiences - one human, one machine. The machine doesn't actually care how long your lines are - this is an optimization for humans.
And I hear you about fixing the tools. Wouldn't it be easy if everyone used the same editor. But alas, this isn't a problem with the tools. It's an inherent limitation of text. That "figuring out visual structure" bit only works if your editor deeply understands your language. And different editors understand languages to different degrees and in different ways.
They say parsing is a solved problem, but I dare you to parse Ruby or Python correctly.
- chrismorgan 13y agoWhile Ruby and Perl cannot be parsed, Python can be parsed correctly.
- elnate 13y agoI don't understand what you mean by parsing if not what the interpreter does. Can you give an example?
- SoftwareMaven 13y agoPerl (and I assume Ruby from the comment) requires the running context of the interpreter to make decisions about how to interpret some code constructs. Because you need the running state, it is not parseable.
- lmm 13y agoParsing as in determining what constructs different lines represent, without running them. Imagine e.g. a documentation generator that needs to figure out what all your methods and parameters are, but not actually execute them (obviously there are many other use cases). A friend at an old job had a piece of perl code where one of the lines would be a comment or not when you ran it, depending on user input. He would bring it out whenever someone suggested writing something in perl.
- Mithaldu 13y agoTechnically correct. Practically there is a tiny subset of Perl that the parser cannot decide correctly, which is used by virtually nobody. Almost all of the code on CPAN can be parsed just fine by this module: https://metacpan.org/module/PPI https://metacpan.org/module/PPI
- jayferd 13y agoUh, ruby can be parsed, it's just hard. It's waaaay saner than perl.
- damncabbage 13y agoIf you emulate the way the MRI parses it, sure. For example: # Is this some_method with an empty block, or an empty hash? some_method {} # Is this a regex or a comment? # # It depends how many arguments "whatever" takes, and you # don't know that until you run the code that defines it. # # Interpretation is implementation-defined. It just so # happens that the MRI determines that the below ISN'T a # regex because it has a SPACE character just after the "/". whatever / 25 ; # / ; raise SystemExit.new;