4 ms·
Does it strike anyone else as odd that garbage collection is used in such a resource constrained environment? Also tangent question, what is it about languages
by ionforce 12y ago
Does it strike anyone else as odd that garbage collection is used in such a resource constrained environment?
Also tangent question, what is it about languages like Python and Ruby that make it more amenable to reimplementation than Perl?
- Demiurge 12y agoTo take a stab at the second question, I think BNF that fits on one page https://docs.python.org/3.4/reference/grammar.html https://docs.python.org/3.4/reference/grammar.html vs http://perldoc.perl.org/perlfaq7.html#Can-I-get-a-BNF%2fyacc%2fRE-for-the-Perl-language%3f http://perldoc.perl.org/perlfaq7.html#Can-I-get-a-BNF%2fyacc... This basically means Perl is very complex and its grammar can be self contradicting, such that behavior is undefined. C++ has a similar problem to a lesser extent.
- riffraff 12y agoTo expand on the non-syntax, perl has an incredible amount of language-level features, which may appear very weird to people who have only seen it from afar. For example, perl formats[0] are language-level support for generating formatted text reports and charts, which is basically a whole sublanguage (much like perl regexen). [0] http://perldoc.perl.org/perlform.html http://perldoc.perl.org/perlform.html
- stcredzero 12y agoWhen I looked at such things last, Python had about 29 terminals & nonterminals in its grammar. Ruby had 110. (These are numbers I remember from playing with particular parser libraries, so YMMV.) By contrast, a commercial Smalltalk with some syntax extensions had 8. I have no idea about Perl, but I'd guess it's about the same as Ruby.
- dragonwriter 12y ago> To take a stab at the second question, I think BNF that fits on one page Maybe for python, but not for Ruby. Ruby is not particularly simple to parse (though it may be simpler to parse than Perl, and clearly seems to be simpler to implement -- or perhaps its just that more motivation exists to implement it.)
- Demiurge 12y agoFirst google result: http://www.cse.buffalo.edu/~regan/cse305/RubyBNF.pdf http://www.cse.buffalo.edu/~regan/cse305/RubyBNF.pdf I think 2 pages is not bad :) The point is, Perl is just impossible to formally define, it depends on the implementation to make arbitrary choices. This means multiple implementations are much harder, if possible.
- dragonwriter 12y ago> First google result: http://www.cse.buffalo.edu/~regan/cse305/RubyBNF.pdf http://www.cse.buffalo.edu/~regan/cse305/RubyBNF.pdf Yeah, but its not: 1) One page, or 2) Current (it claims to be for Ruby v1.4), or 3) (apparently, I can't verify this for the version of Ruby it claims to represent) Accurate [1] [1] http://stackoverflow.com/questions/663027/ruby-grammar http://stackoverflow.com/questions/663027/ruby-grammar But, yes, Ruby can be parsed independent of being execution, which makes means you can separate the work of a separate implementation into (1) building (or reusing) a parser, and (2) building a system to execute the result of the parsing. Being able to divide the work (and, as a result, to share the first part between different implementations) makes it easier to implement.
- Demiurge 12y agoI don't think it's as much about ease of implementation as it is about the finality of it and formal verification of completeness of any implementation. But of course, those are very much related :)
- dragonwriter 12y ago
- maxerickson 12y agoI'm not sure about Ruby, but Python is a smaller language than Perl. Avoiding parsing complexity is also an explicit design goal in Python (where Perl probably somewhat prefers convenience).
- astrobe_ 12y agoActually, reference counting needs some garbage collection in order to handle cyclic structures. I believe that basically refcounting is more space-efficient and less CPU-efficient. I'm not totally sure about this, and it might depend on the actual techniques used on both sides as well. If a justification is to be given for this switch, I would say that increasing RAM size is generally easier than increasing CPU speed. Obviously, operating on a GC is never ideal on a resource-constrained system, but most modern scripting languages wouldn't be the same without it. The only example I know of, of a scripting language that has the feeling of the scripting language but without using a GC is Newlisp (http://www.newlisp.org/MemoryManagement.html http://www.newlisp.org/MemoryManagement.html).
- phkahler 12y agoWhy yes, yes it does. But it's complex. The rule for embedded C is to never call malloc() or free(). You manage everything because heap fragmentation could lead malloc() to fail and then your system crashes. So given that, reference counting would seem to use more space for the same set of variables which would be bad. OTOH, the pause that may occur while collection happens can be fatal to such a system. The trade here is memory use vs non-deterministic run time. I'll take the memory use any day in such a system.
- TorKlingberg 12y agoIt depends on how resource constrained and real-time the system is. I imagine Micro Python will not be used in cases where you never use malloc().
- mech4bg 12y agoThe kickstarter updates for this project are a good resource for the thought process behind its design and how it was all implemented, very interesting stuff: https://www.kickstarter.com/projects/214379695/micro-python-python-for-microcontrollers/posts?page=7 https://www.kickstarter.com/projects/214379695/micro-python-...