1,014 reputation
710
bio website py.phzzz.co.uk
location England, United Kingdom
age 22
visits member for 3 years, 7 months
seen 26 mins ago

22m
comment How does a stack VM manage with only one stack?
Do you know how this is done on physical machines? I can't tell you the specifics from any VM, but on a physical machine your end instruction would also have to do something to tear down the stack frame. You always maintain a pointer to the start of your functions little bit of stack. The return address is just above that, not at the very end.
1d
comment “Immutable” interfaces
The distinction for no /observable/ side effects is mostly for things like logging, caching, lazy eval, et cetera. Read observable as "functional"--as in, if you removed them, the program's correctness would not change. In this case, your side effects are behavioral and your function is impure.
Jul
24
comment question use C++
@user143937: If you "just want to make sure", look at codereview.SE instead and give them your solution, not a copy-pasted problem.
Jul
16
comment Does it make sense to use interfaces if you don't have polymorphism?
@m3th0dman: Interfaces are giving you polymorphic behaviour whether you like it or not. If new ClientA(new ImplementationB()) is valid code that works, and yet breaks at runtime, then you have polymorphism, and it is being misused. Interfaces are not just categorising, they are abstracting over behaviour.
Jul
15
comment Does it make sense to use interfaces if you don't have polymorphism?
@m3th0dman: Then this is a clear misuse of polymorphism.
Jul
15
comment Does it make sense to use interfaces if you don't have polymorphism?
If I use ImplementerB in ClientA, will it break?
Jul
9
comment Python API: Extension Module or Pure Module
What is your software? If it's (Something) but /really/ fast then your choice is made for you. If it isn't, then is the speed hit even relevant?
Jul
8
comment Why isn't there a next operation on enums?
A quick check in Java implies you can reference enum members in the ctor of another member so long as it's been defined already. Sunday, Saturday(Sunday), Friday(Saturday),... could work. Alteratively, a .next method that's a little bit reflective would work. I think the real reason is because, as you say, not all enums have a meaningful or trivial ordering.
Jul
4
comment How many mistakes does a good software developer make?
I've been programming for over a decade now. I recently wrote some networking code which worked, first time, perfectly. Zero flaws throughout the whole project. Every time anything went wrong, my first thought was that I'd finally discovered the bug in that piece of code.
Jul
3
comment Is there a real advantage to dynamic languages?
@Doval: Oh, sorry, I wasn't even thinking about that. Replace logging with memoisation or something, then. The important part was if your function only takes a concrete type in C# or Haskell, your flexibility is limited. In either language, if you use the tools they give you for polymorphic behaviour, you get a lot of flexibility. I don't think this is the problem typeclasses were intended to solve, because they don't solve that problem. They're better, in many ways, than subtyping polymorphism, but they don't fix this particular issue.
Jul
3
comment Is there a real advantage to dynamic languages?
@Doval: Yes, I understand the advantage of typeclasses, but they don't help you if your function is not of type (Barkable b)=>b->Whatever. If your function is of type Dog->IO() and you want to pass in a logging auto-proxy you're just as stuck as a method in C# or Java of type void(Dog).
Jul
3
comment Is there a real advantage to dynamic languages?
@Doval: Because you're using their systems for polymorphism. You don't get that problem in C#/Java either if they're defined on interface types. Typeclasses are not helpful if you have a function from concrete type T to concrete type K, and indeed you may be worse off in those languages due to not having the same kind of subtyping relationships an OO language might have if your lazy library developer has left everything open for inheritance. A well written program is flexible in any language, but dynamic languages can make even poorly written programs flexible.
Jul
3
comment Is there a real advantage to dynamic languages?
@Doval: So? You can't define anything /but/ objects, and you have a contract to stick to just as much as if you were in a strictly typed language. Just because I wrote makeItBark with my own types in mind doesn't mean you can't use yours, wheras in a static language it probably /does/ mean that. Besides, you don't need to make a class, as shown in my original snippet. Anything that supports the right accessors will work, whether you're patching them into an existing class, making your own, using a namedtuple, a dict with a wrapper to direct d.k to d[k], /whatever/.
Jul
3
comment Is there a real advantage to dynamic languages?
@Den: Essentially. There's very little good reason why many functions at all should only accept a specific type, rather than, as you say, anything with sticks to some contract.
Jul
3
comment Is there a real advantage to dynamic languages?
@Prog: The real advantage of dynamic languages is when it comes to describing things which is really hard with a static type system. A function in python, for example, could be a function reference, a lambda, a function object, or god knows what and it'll all work the same. You can build an object that wraps another object and automatically dispatches methods with zero syntactic overhead, and every function essentially magically has parametrized types. Dynamic languages are amazing for quickly getting stuff done.
Jul
3
comment Why does C# have much more features than Java?
Biased answer: Because the C# design team know what they're doing. More reasonable answer: C# was designed with the knowledge of Java's failures and without the dogmatic "only pure OO" (that they didn't even quite hit). Half of those features were bulk-imported from Lisp and Haskell, two languages Java steadfastly refused to be inspired by until java 8, and the others are sanity improvements made blindingly obvious by Java's lack of them.
Jul
3
comment Is there a real advantage to dynamic languages?
makeItBark(collections.namedtuple("Dog", "bark")(lambda x: "woof woof")). That argument isn't even a class, it's an anonymous named tuple. Duck typing ("if it quacks like a...") lets you do ad hoc interfaces with essentially zero restrictions and no syntactic overhead. You can do this in a language like Java, but you end up with a lot of messy reflection. If a function in Java requires an ArrayList and you want to give it another collection type, you're SOL. In python that can't even come up.
Jul
3
comment How does the “Fourth Dimension” work with arrays?
While you should avoid linking "dimensions" with physical space, for data visualisation this is often impossible, but yes, it gets very very confusing when you start talking about whether an nth dimensional output set can be linearly separated by a hyperplane. Don't think about that stuff if you can avoid it.
Jul
3
comment What's wrong with this pointer?
Bar *foo;, or as I prefer to set it out, Bar* foo;, is making a variable called foo of type pointer to Bar. It is not a Bar. There are no Bars in your program, so dereferencing foo will crash. If you're lucky.
Jul
2
comment How bad is it calling println() often than concatenating strings together and calling it once?
@JerryCoffin: If we're going down to ad hominum there's no purpose continuing the discussion.