10,547 reputation
12346
bio website
location
age
visits member for 3 years, 11 months
seen 2 hours ago

Aug
28
comment From a technical point of view, could JavaScript be compiled instead of interpreted?
Note however that asm.js is only a subset of JavaScript in the sense that asm.js code can be run by JavaScript implementations. It's not a subset in the sense of being able to compile some JavaScript programs (only very few exceedingly trivial ones, and that by coincidence rather than design). It's better to think of it as "assembly language encoded to run in legacy browsers", not "JavaScript variant made to be compiled"
Aug
28
comment From a technical point of view, could JavaScript be compiled instead of interpreted?
@whatsisname I guess it depends on how you define "compiled". Would unrolling the interpreter loop be compiled? Would slightly optimizing the unrolled interpreter loop make it compiled? How about if I optimize it some more? Where is the line? The program above is turned into a standalone binary that performs the same function as the JS program, and any such program will necessarily contain interpreter-like code sequences. Calling it compiled is justified IMHO.
Aug
28
answered From a technical point of view, could JavaScript be compiled instead of interpreted?
Aug
27
comment Is there any danger in writing raw bytes to a file?
There is no EOF character/sequence.
Aug
27
comment Is it a good practice to declare instance variables as None in a class in Python?
The space taken is by far the least important reason this convention stinks. It's a dozen bytes per name (per process). I feel like having wasted my time just reading the part of your answer pertaining to it, that's how unimportant it the space cost.
Aug
27
comment Is it a good practice to declare instance variables as None in a class in Python?
@Doval There is an extraordinarily good reason to prefix attribute names with _: To indicate that it is private! (Why are so many people in this thread confusing or half-confusing Python with other languages?)
Aug
27
comment Is it a good practice to declare instance variables as None in a class in Python?
@MasonWheeler Python doesn't have overloading, so no class can have more than one constructor.
Aug
26
comment How do I move away from the “for-loop” school of thought?
@Doval From the context I assumed OP was speaking absolutely (compared to a C loop, it is slow).
Aug
26
comment How do I move away from the “for-loop” school of thought?
@Doval Unfortunately not -- in NumPy. A Python for loop performing elementwise addition can easily be several times(!) slower than the vectorized NumPy operator (which is not only written in C but uses SSE instructions and other tricks) for realistic array sizes.
Aug
23
comment Avoid Code Repetition in Condition Statements
Where does this need multiple return values? Multiple return statements, yes, but virtually every language allows that.
Aug
22
comment If there's no problem treating a statement as an expression, why was there a distinction in the first place in some programming languages?
An if whose branches return different types is simply illegal in such a language. void methods don't exist, instead the unit type () is used which has a value (only a single, and hence meaningless, one) to be returned. And unless you pursue purely functional programming (in which case none of your concerns even arise), you will have a operator to "ignore" a value, i.e. execute an expression for side effects and then return (). Armed with that, you can trivially write if (c) { f(); } else { g(); } where f and g return different types and ; is the execute-and-ignore operator.
Aug
22
comment If there's no problem treating a statement as an expression, why was there a distinction in the first place in some programming languages?
A distinction between expressions and statements doesn't necessarily help with if (a = b), as long as assignment is an expression (it's one in Java and C# which address this problem through other means). Making assignment a statement would help, but equally well one can restrict if to boolean values (Java, C#) and in a expression-oriented language, additionally make it the moral equivalent of a "statement": An expression that returns the unit type (), which is what Rust does.
Aug
21
comment Performing a Depth First Search iteratively using async/parallel processing?
So it's GetSubItemsAsync that takes ages? You could start each of those tasks as soon as you have the right SubId to start it, and when any of them finishes, process the newly discovered item (i.e. start but don't await the sub-item-fetching tasks for that item too). Naturally, how much this can help depends on the nature of GetSubItemsAsync (is it CPU-bound? IO-bound?). Still, if your graph has a diameter of n, there's no way around a total minimum latency of n * latencyOfGetSubItems.
Aug
21
comment Performing a Depth First Search iteratively using async/parallel processing?
Between distributing the work (I don't see a way to do this without synchronizing access to the stack or stacks at least occasionally), synchronizing whatever mechanism you use to not re-visit nodes (e.g. flag in the nodes or external set data structure), and the extra work to accumulate the results from several threads, this doesn't seem like a good candidate for parallelism. Why do you want to parallelize this part?
Aug
21
comment And at what point of modification to the original does source code with no license become owned by me?
@toasted_flakes And code with a license attached is also copyrighted. A license is the copyright holder allowing you to do various things with the code.
Aug
21
comment Can regexp be used to check for palindromes?
@ratchetfreak But java.util.regex.* aren't regular expressions in that sense, they're more powerful than regular languages. Feel as you will about that, but ignoring it doesn't help, it just misleads.
Aug
18
comment When is type testing OK?
"Type checking" almost always refers to checking whether code observes the static typing rules of the language. What you mean is usually called type testing.
Aug
18
comment What does “context-free” mean in the term “context-free grammar”?
What does this add to the existing answers? Also, a production rule with two or more non-terminals on the left hand side isn't context free either.
Aug
13
comment Optimizing code by using registers, but what if they are not enough in number?
@JohnR.Strohm My point exactly, read again.
Aug
12
comment Is this looping solution possible with recursion?
The recursion limit is not a concern here. Even for very short max_values the number of combinations quickly grows beyond reason. [2] * 100 is probably already too large to be enumerated on a physical machine (2^100) and it only needs 100 levels of recursion. More realistic is at most a dozen recursive calls.