Reputation
Top tag
Next privilege 5,000 Rep.
Approve tag wiki edits
Badges
2 19 33
Impact
~180k people reached

Jun
30
comment How do I design a subclass whose method contradicts its superclass?
If a contract was just a method signature then it would be useless to ever specify them explicitly, since the signature would enforce it already.
Jun
22
comment What problem do algebraic data types solve?
Your last sentence is kind of like telling someone that "ships solve the same problem as airplanes: transportation -- they just take a different approach to it". It's a completely correct statement, and also a pretty useless one.
Jun
17
comment What's the point of implementing a Stack using two queues?
(...cont'd) If you think about the uses of priority queues, it is generally true (i.e., there exists a statistical trend) that those enqueued later are still dequeued later than those enqueued earlier. For example, breadth-first-search is an approximation to Dijkstra's algorithm in many cases, even though in particular instances it might not be a great approximation. A stack is never any kind of approximation to a queue. It has precisely the opposite behavior in every situation, so calling it a queue is completely nonsensical.
Jun
17
comment What's the point of implementing a Stack using two queues?
The whole point of a queue is that your enqueue time should have some vague sort of inverse correspondence with your dequeue time. In other words, with any kind of queue, given no additional information, then your best guess is that those enqueued later will be dequeued later. Sure, it might not be 100% accurate, but "queue" still (statistically) describes the overall trend. But with a stack, which exactly behaves in the opposite fashion, this is strictly the worst possible guess--at that point, it bears exactly zero resemblance to a queue. (That's 0%! Not even 1%!)
Jun
17
comment What's the point of implementing a Stack using two queues?
@yoniLavi: I don't disagree that it's popular nomenclature, but that doesn't imply it makes any sense. A calling a stack a "LIFO queue" makes as much sense as calling ethernet "wired Wi-Fi".
Jun
17
comment What's the point of implementing a Stack using two queues?
"A stack is a (LIFO) queue"... uhm, a queue is a waiting line. Like the line for using a public restroom. Do the lines you wait in ever behave in a LIFO fashion? Stop using the term "LIFO queue", it's nonsensical.
May
30
comment What's the proper way to model this real-world activity that seems to need circular references in OOP?
Contrary to the existing answers I think your design is poor and a proper fix should not result in circular references.
May
26
comment Why can't there be any implicit conversions?
@PieCrust: To be honest I would never expect len(100) to return 3. I would find it much more intuitive for it to calculate the number of bits (or bytes) in the representation of 100.
May
24
comment Can you implement “object-oriented” programming without the class keyword?
If you've ever seen WindowProc in the Windows API documentation, it's exactly the OOP dispatcher function you're trying to invent here, in C.
Apr
12
comment Ambiguity of seemingly clear method names in APIs
+1. Regarding your comment: returning the data is ideal, except that it's a huge performance hit to allocate a new buffer every time, so it's not done in practice (as you can tell in Stream).
Apr
12
comment Ambiguity of seemingly clear method names in APIs
@BenAaronson: I guess, but that's neither the real problem here nor can I think of better names. The problem still exists inside the other methods in MyComponent and in derived classes, doesn't it?
Mar
24
comment Do dynamic typed languages deserve all the criticism?
@PaulNathan: You're thinking too hard. The question was asking about dynamically typed languages, and this answer mentions Java as though it's dynamically typed.
Mar
24
comment Do dynamic typed languages deserve all the criticism?
@PaulNathan: Did you read the question?
Mar
24
comment Do dynamic typed languages deserve all the criticism?
I like your answer but Java isn't dynamically typed...
Mar
24
comment Method extraction vs underlying assumptions
+1 One thing that's important to note is that there is a cost to splitting up a big method into smaller chunks: it's typically not useful unless the preconditions and postconditions are more relaxed than they would have been originally, and you can end up having to pay the cost by re-doing checks that you would have otherwise already done. It's not a completely "free" refactoring process.
Mar
24
comment Method extraction vs underlying assumptions
Relevant: Is it always a best practice to write a function for anything that needs to repeat twice?
Mar
21
comment When is it a good idea to force garbage collection?
+1 for that paragraph as well. I find it shocking that people think a computer program written by someone else must necessarily understand the performance characteristics of their program better than themselves.
Mar
16
comment What is the reason of using an interface versus a generically constrained type
Interface methods are indirect calls, whereas type methods can be direct calls. So the latter can be faster than the former, and in the case of ref value type parameters, might actually modify the value type.
Feb
23
comment What about LISP, if anything, makes it easier to implement macro systems?
Macros need to execute though, at that point you're already writing an interpreter for the language.
Feb
3
comment Is a 1 < 10 comparison less expensive than 1 < 1000000?
It could be less expensive if it were in the critical path, but it's almost surely not.