10,282 reputation
12345
bio website
location
age
visits member for 3 years, 11 months
seen 59 mins ago

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.
Aug
12
comment How can a statically typed language support duck typing?
@Doval That is certainly part of the appeal, but the Pythonista in me and some people I've talked to fights toe and nail against having to write as little boilerplate as instance Blah MyType blahFoo = myFoo.
Aug
11
comment How can a statically typed language support duck typing?
To be clear: Type classes and similar ad-hoc polymorphism usually aren't considered duck typing though, since one must explicitly opt into the type class (even if doing so can happen anywhere in the program) rather than magically having it work after defining just the method.
Aug
11
comment How can a statically typed language support duck typing?
I'm not sure whether C++ templates can be called a structural type system (I think I've never seen it referred to as such). There's not really any type system that could be structural, it just substitutes the types and sees if that monomorphized code is valid.
Aug
10
comment Reconstructing a huffman tree using minimal information in the header
struct Node { ... struct Node left; ... } wouldn't work at all. See my answer for everything else.
Aug
10
answered Reconstructing a huffman tree using minimal information in the header