Live data from Hacker News

One of the Best Bits of Programming Advice I ever Got

objology.blogspot.com

91–94 of 94 posts

Re: One of the Best Bits of Programming Advice I ever Got

#91

Earlier quoted context omitted.

> Being able to capture all possible 'state mutations' of a value in one assignment is good. I think there's a duality here. If there are 20 buttons, each of which can affect some of 30 counters, then the Haskell code would say "this counter is affected by these buttons", while imperative/OO code would say "this button affects these counters". It's not obvious to me that the former way of organizing code is better.

You are still missing the point. In imperative programming there is no guarantee that the counter isn't modified in some place else or wrongly. In the end it's just an integer that allows all kinds of mutations. The possible value changes in the Haskell FRP example, on the other hand, are completely described. There is no other manner in which the value can change.

OOP also has a way to guarantee that the counter can only be changed by calls from specific parts of the code, it's called encapsulation. For example, the counter could be an object that subscribes to button events, and the counter's value could be a private member variable of that object. What exactly is the win from FP here?

Re: One of the Best Bits of Programming Advice I ever Got

#92
post #81

Meh. I'm working on a video game at the moment, and have read lots of advice like this. My old game engine experiments all used 'Entities' to describe objects in the game world, and these 'Entities' were created, deleted and invoked by an 'EntityManager' (kind of half factory & half controller). Every game tick, the EntityManager calls a 'tick' method on all the current game entities and facilitates communication bet…

The entity boss part seems like it's just an array of objects you perform actions on. It's not a description of the goal of the object, it's an internals-level view of how it does it.

Maybe there's another more fundamental behavior or dataset that would suggest a better name?

Perhaps Scene or World, depending on the things the EntityManager was doing. If it's reloading them it's like a scene, if it's changing gravity it's more worldy...

Re: One of the Best Bits of Programming Advice I ever Got

#93
post #52

Well, this is one of my reasons for python over Java as a programming language. There are some procedures that don't fit naturally into a class or object and I should be allowed write functions for them. I was a OOP fan, when i learnt c++, but when i learnt java was put-off by its' requirement of needing a class. I am learning Haskell now, and am a little infatuated with FP, but not sure will enjoy using it a couple…

Just curious, why downvote. is anecdotal evidence frowned upon here? Or only opinionated, argumentative positions welcome??

Re: One of the Best Bits of Programming Advice I ever Got

#94
post #89
post #32

Earlier quoted context omitted.

Functional programming and objects are not orthogonal as you suggest.

Yes, they pretty opposite. Objects should have identity and can be distinguished by identity alone. They are not referentially transparent because of that. In "x = new O(); f(x,x)" you cannot substitute "new O()" into both occurrences of x. Functional values do not have identity and you cannot tell apart 2 and 1+1. Functional values are referentially transparent. In "x = 1; y = x+x" you can change x to 1 in the defin…

Again, they're not opposite. You can create most of the properties of an object with a closure and versa vice.

http://c2.com/cgi/wiki?ClosuresAndObjectsAreEquivalent

Post reply on HN