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

Aug
12
comment Should I put newlines before or after binary operators?
I don't know about you, but I rarely screw up indentation anywhere but the single line I currently work on, and when I do, I'm told by a ludicrously long diff and by syntax errors. Speaking of which, how many of those mishaps leave all your code in a state where it's accepted by the parser? (Let alone a style guide checker.) All things considered, I still believe it's incredibly unlikely to wind up with valid but wrong code due to this.
Aug
12
comment Should I put newlines before or after binary operators?
I see, but it doesn't do that either. At least I've never seen it happen (and I strictly follow PEP 8's rule about putting newlines after operators) and I cannot imagine non-contrived code which is valid with the newline before the operator but not after the operator. For example, code like in your first snippet also errors (due to indentation). Does anyone not add indentations when splitting a line?
Aug
12
comment Should I put newlines before or after binary operators?
No you shouldn't do that in Python, mostly because does not have the effect you claim it has. A trailing operator doesn't cause a line continuation; a backslash or having unclosed parentheses, brackets or braces does.
Aug
9
comment Abstracting away the type of a property
Let me get this straight. You're considering obj.foo = some_foo as (semantically identical) alternative to obj.foos.append(some_foo)/obj.add_foo(some_foo)? If so, WTF. The former with the semantics of the latter would be a HUGE violation of the principle of least astonishment.
Aug
9
comment Is there a programming language where 1/6 behaves the same as 1.0/6.0?
Weak/strong typing is ill-defined (as wiki also implies), please avoid it and be specific. I take it your definition bans implicit conversion, but not ad-hoc polymorphism? If so, consider Haskell, which has no implicit conversions but pretty well-executed (as in, works 99% of the time and can be comprehended by mortals) numeric polymorphism. And why would this be astonishing? It would be far more astonishing (not to say annoying) to me if I had to add a number of dots to every single instance of any operator, depending on the exact precision I wish.
Aug
9
comment Is there a programming language where 1/6 behaves the same as 1.0/6.0?
Why the heck would weak typing (whatever that's supposed to mean) be necessary? Just define / to (also) mean float division in the case of both arguments being integers.
Aug
7
comment parsing terminology: comments+whitespaces vs actual code
An AST is more specific AFAIK - whitespace and comments might be stripped by the tokenizer and the rest may go into a concrete syntax tree first.
Aug
7
comment How to deal with code reuse philosophy?
Is the "was" in the first sentence a typo'd "has"?
Aug
7
comment Does multiple inheritance violate Single Responsibility Principle?
Just to be clear, you also believe implementing multiple interfaces violates the SRP?
Aug
6
comment Monkey Hunter algorithm - Interview question
#2 and #3 is in fact stated (ammo kills single monkey in single tree; movement is random), #4 is implied to be false.
Aug
6
comment Monkey Hunter algorithm - Interview question
Does "fewest shots possible" refer to best-case, worst-case, or average-case number of shots? Or perhaps amortized for hunting multiple monkeys simultaneously? (I swear to god, coming up with these questions is a hundred times more fun than actually giving the answer they're looking for.)
Aug
6
comment Monkey Hunter algorithm - Interview question
Also, is the number of trees finite, and if so, how many are there?
Aug
6
comment Monkey Hunter algorithm - Interview question
@Brian Sure, the expected number of shots is (or should be, I'm never 100% confident with these things) finite, but at least in the case of a simplified 2D forest there's probably a better way, and intuitively it seems the expected number is pretty bad.
Aug
6
comment Monkey Hunter algorithm - Interview question
Is this a simplified 2D (trees have two neighbors each) forest, or a simplified 3D (trees have K neighbors each) forest, or a complicated 3D forest (trees have 0-K neighbors, and the number depends on how far neighbors may be away from each other)?
Aug
6
comment Monkey Hunter algorithm - Interview question
If the monkey's choice is indeed truly random, this actually stands a chance of never hitting the monkey. It might as well jump between the same two trees forever.
Aug
5
comment Make use of design patterns in C?
You two must be defining the strategy pattern awfully broad then. To me, that's just basic use of variables. So basically everything where a nontrivial effect depends on the value of some storage location (and is not explicitly decided via branching by the causing code) is the strategy pattern?
Aug
5
comment Make use of design patterns in C?
@OskarN. I'm afraid I don't follow. How does the concept of having a couple of streams for everyone to write to have anything to do with the strategy pattern, which is a design pattern by which an implementation of an algorithm is chosen at runtime?
Aug
5
comment Make use of design patterns in C?
Excuse me, how are stdout/stderr/stdin instances of the strategy pattern? They are just global variables. Sure, you can replace them to change where certain functions write to/read from, but that's pretty basic stuff and a way to avoid lots and lots of extra parameters.
Jul
23
comment Python mutable default argument: Why?
On a language design level I mean. The Python language definition currently states that default arguments are treated the way they are; it could equally well state that default arguments are treated in some other way. IOW you are answering "that's how things are" to the question "why are things the way they are".
Jul
22
awarded  Enlightened