9,543 reputation
12241
bio website
location
age
visits member for 3 years, 9 months
seen 5 hours ago

8h
comment Is there a reason to define type aliases in any program
"Custom types" usually include aggregate types (structs, classes, unions, and so on). Are you intentionally ignoring those and focusing on typedef? If so, perhaps you should update the question and title to refer to type aliases/typedefs.
1d
comment Are there technical limitations or language features that prevent my Python script from being as fast as an equivalent C++ program?
The string "a" is not a good example for the first bullet point. A Java string also has considerable overhead for single character strings, and but it's constant overhead that amortizes quite well as the string grows in length (one to four bytes oer characters depending on version, build options, and string contents). You're right about user-defined objects though, at least those that don't use __slots__. PyPy should do much better in this regard but I don't know enough to judge.
1d
comment Are there technical limitations or language features that prevent my Python script from being as fast as an equivalent C++ program?
@nwp No, that one's easy, see PyPy. Trickier, still open, problems include: How to overcome the start up latency of JIT compilers, how to avoid allocations for complicated long-lived object graphs, and how to make good use of the cache in general.
1d
comment Do VMs use one stack for everything?
@randomA I think you're wrong. Stack machines are a thing (in fact, probably the single most popular design for VMs) and they fit that exactly. It also meshes better with the actual question (whether that is the same stack as the call stack).
1d
comment Do VMs use one stack for everything?
@randomA Where does parsing enter the picture? This question seems to be exclusively about the execution of the program, not analysis.
1d
comment Do VMs use one stack for everything?
@randomA Quite the opposite for many VMs, which use a stack (though not necessarily the same stack) all the time, even in cases where a machine code compiler could and would use registers.
2d
comment can non-programing fizzbuzz work?
Isn't the whole point of FizzBuzz that it's so incredibly basic that it just weeds out the people who simply "can't program their way out of a wet paper bag"? The questions you give, and others along those lines, are far more specialized and may very well weed out decent engineers (especially the second one) that just don't have that particular piece of knowledge at hand right now.
2d
comment Why was the first compiler written before the first interpreter?
@supercat Yes, that's a good point.
2d
comment Why was the first compiler written before the first interpreter?
@gnasher729 Well, Forth ;-) The VM, and to some extent the language, needs to be designed for this. For example dynamic typing would take its toll, a statically typed or untyped language makes things easier. You make the first byte signify the opcode, store the code for opcode i at BASE+(i<<k) for some appropriate k, then you can dispatch each opcode in three instructions, give or take one depending on how fancy the instruction set is: (1) Get opcode. (2) Calculate code address. (3) Jump to that address. Add more if the instruction has arguments (not always necessary for stack machines).
2d
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.