10,092 reputation
12343
bio website
location
age
visits member for 3 years, 10 months
seen 4 mins ago

Jul
28
comment Why was the first compiler written before the first interpreter?
I don't know much about 1950s computers, but at least for the simple von Neumann machines of later decades, interpreter overhead would be two to five instructions (maybe four to ten cycles total) per interpreted instruction: Decode, indirect jump, maybe decode additional arguments. If you make the interpreted instruction set sufficiently high-level (so you execute several machine instructions per interpreter instruction) this would be less than 90% and perhaps even acceptable. See also: Forth.
Jul
27
comment the perils of using eval() for dynamic object creation — is this a valid argument in a consenting-adults culture?
There is zero need for eval in your example. Store the actual classes in testlist (i.e. dict(cls=Test, ...)) and have simpler code that runs faster too. Same goes for most other uses of eval and friends, only a small fraction of the cases where people are tempted to use eval actually call for eval.
Jul
26
comment What should I do and know before I start writing C?
There's nothing you can do to make your C code good right off the bat, except perhaps learning a full language that's very C-like (of which there are very few). Don't be afraid to write crappy code, just learn why it's crappy. Your early Java programs were bad, and now you're good at Java, right?
Jul
26
comment Is immutability very worthwhile when there is no concurrency?
@DavorŽdralo As far as high level languages' abstractions go, pervasive immutability is rather tame. It is just a natural extension of the very common abstraction (present even in C) of creating, and silently discarding, "temporary values". Perhaps you mean to say it's an inefficient way to use a CPU, but that argument has flaws too: Mutability-happy but dynamic languages often perform worse than immutable-only but static languages, partly because there are some clever (but ultimately quite simple) tricks to optimize programs juggling immutable data: Linear types, deforestation, etc.
Jul
25
awarded  Enlightened
Jul
24
comment Is immutability very worthwhile when there is no concurrency?
Concurrent modification need not mean threads. Just look at the aptly named ConcurrentModificationException which is usually caused by the same thread mutating the collection in the same thread, in the body of a foreach loop over the same collection.
Jul
24
comment Why don't Python and Ruby make a distinction between declaring and assigning a value to variables?
How's that? I mean, I completely agree that it's better to not have bugs in the first place (I just don't see declarations helping with that to any significant degree). However, the need to read the code doesn't make debugging even less desirable: Reading is an integral part of debugging, it's already accounted for (consciously or not) in our feeling that it's hard work and takes a long time and is generally undesirable. If anything, this connection elevates the importance of readability since even debugging benefits from it.
Jul
24
comment Why don't Python and Ruby make a distinction between declaring and assigning a value to variables?
@AlexanderGelbukh Note that the bug you describe is due to an interaction of several PHP features (chiefly references) and IIUC can't happen in that way in other languages lacking declarations. As for writing/debugging: Note that most debugging strategies (from low-tech "staring at it until it becomes clear" to fancy time-traveling debuggers) include a significant chunk of reading the code being debugged.
Jul
23
comment Why don't Python and Ruby make a distinction between declaring and assigning a value to variables?
@AlexanderGelbukh I don't know PHP well enough to identify the cause, would you mind explaining?
Jul
19
answered Why don't Python and Ruby make a distinction between declaring and assigning a value to variables?
Jul
19
comment Why don't Python and Ruby make a distinction between declaring and assigning a value to variables?
@Akash That does not seem related to the question at all, it remains equally valid if run through s/variable/name/g.
Jul
17
comment Do modern languages still use parser generators?
C and C++ need symbol table information during parsing (or accept a far less specific parse tree where no distinction is made between, for example, expression statements and variable declarations). But I wasn't thinking of those. Languages like Java, Lisps, JavaScript, Ruby, Python, Go, Rust, Scala, Swift, Haskell (and probably several more, maybe C# and ML too?) don't need any such information to build the kind of AST you'd want anyway. Many of them actually have LL(1) grammars, or even LALR grammars.
Jul
17
comment Do modern languages still use parser generators?
And about the second area: Many many major real programming languages are not context sensitive in any sense that applies (you'd have to refer to the set of all valid programs after type checking and such, which is never what a hand-written or generated parser tries to parse). It's true that hand-written parsers are more flexible, and this is useful for some languages, but mostly in the realm of error recovery and reporting, incrementality, etc. -- parser generators are rarely eschewed because of recognition power (whether you'd want to write such a grammar is a different story). -1
Jul
17
comment Do modern languages still use parser generators?
Citation for the performance claim please? Being table-driven can be a significant performance optimization and generators have access to algorithms that are very efficient but virtually never implemented by hand (precisely because they are an impenetrable mess of tables and magic numbers).
Jul
17
comment General recursion to tail-recursion
Oh course the downside is that you build lots and lots of closures (the continuations). It's not a good way to improve performance or memory use.
Jul
17
comment Hash function for progressive changes
@StefanoBorini This is known as a hash list, and is generalized by Merkle trees. The latter have a couple of advantages, but I don't know if any of those are applicable do your use case.
Jul
17
comment Do modern languages still use parser generators?
Data point: CPython has a home brew LALR parser generator (pgen). Don't know about the rest.
Jul
16
revised How are OOP “objects” and “classes” organized in memory in terms of assembly language?
added 1 character in body
Jul
16
revised How are OOP “objects” and “classes” organized in memory in terms of assembly language?
added 189 characters in body
Jul
16
answered How are OOP “objects” and “classes” organized in memory in terms of assembly language?