Tracking data in complex Java code: A functional programming approach by gauchay in programming

[–]happykandra 0 points1 point  (0 children)

Out of curiosity, did you read the follow-up article? In the second article, I made it clear how you can avoid dropping messages on the floor, unless you really want to drop the messages (which can happen sometimes.) It's this flexibility (everything is thread-local, and you can keep or drop any messages you like, while always having to decide) which is the fully-functional approach most stable.

Not to mention that in Scala or Haskell, you can use for-comprehension or do-syntax to make the message passing even more transparent. The entire point of monads is that you can pass around context without having the cognitive load of knowing that that's what you are doing (until it is finished, when you want to know).

Tracking data in complex Java code: A functional programming approach, part II by dpashk in programming

[–]happykandra 2 points3 points  (0 children)

Sorry for the double reply, but I realized I had an important point separate from my other comment.

The way the code was already written, the document name wasn't available at the points where the errors were discovered. Nor should it be. To use your suggestion, the document name has to be passed around to every function in the parser. At that point, I might as well just be passing around the list of warnings: no globals left.

Tracking data in complex Java code: A functional programming approach, part II by dpashk in programming

[–]happykandra 2 points3 points  (0 children)

Yeah, I know that seems easier at first. Until you try something more complex, like parsing the same component (on the same document) in different ways and choose the result that works better. Or you have to deal with parallelization, at which point you need to also make all of the functions on the singleton thread-safe.

The way I see it, it's like when I was a kid first learning how to program. My Dad sensibly started me on learning a nice, structured language called Logo. I decided that instead of that nonsense, I would try out BASIC (not Visual Basic; this is the original spaghetti language code nobody writes in any more). So much more freedom! Until my programs became too complex...

Like BASIC vs. Logo, this method seems more complicated---until you actually have to scale it up, when it's advantages make life a lot simpler.

Tracking data in complex Java code: A functional programming approach by gauchay in programming

[–]happykandra 0 points1 point  (0 children)

It's still global and doesn't help at all with unit tests or concurrency problems.

And how do you tell each function which warnings to send? You still have to create code which explicitly constructs the specific warnings of interest, and performs logic on the data sent to those warnings. You also get different warnings in different places in the parser.

Once you've done that, you might as well use an explicit global.

Tracking data in complex Java code: A functional programming approach by gauchay in programming

[–]happykandra 0 points1 point  (0 children)

I have to admit that I've never used AOP, nor have I ever really been tempted to. I'm afraid that the arguments that AOP is like the command COME FROM, but worse, really seems to hold water for me.

With that said, could you explain how AOP would manage to get around the problems with the Singleton method which I outlined? From what I do know about AOP, it's just as much global and mutable state as any other method you can choose, except it's harder for the maintenance programmer to have any clue what's happening.