News for hackers. Stuff that matters.
Re:Dynamic programming in Haskell: automatic memoization by EdwardDiego on Tuesday June 20, 2023 @08:08AM (#36402881)
> Magically, fib is now fast

Any code you describe with "Magically" is going to bite you in the arse in about two months. Maybe three.

Leave magic to the guy who also does balloon animals at kids parties.

Re:Dynamic programming in Haskell: automatic memoization by rowanG077 on Tuesday June 20, 2023 @08:14AM (#36402934)
I can't disagree more with this. Running any modern language is magic. If you don't want to use magic. You only get to write assembly or maybe C. Not that I agree with this solution.
Re:Dynamic programming in Haskell: automatic memoization by EdwardDiego on Tuesday June 20, 2023 @08:37AM (#36403127)
You could probably disagree more with it, if you really tried :D

But it's a bit early in the evening for reductio ad absurdum.

After all, we can take it further into absurdity, why aren't we all just programming in hex via a keypad?

Abstraction != magic.

The one bit of SICP that really stuck in my brain was

"Programs must be written for people to read, and only incidentally for machines to execute"

Magic makes the first part far harder. And I apply this to every kind of magic in code.

Annotations in Java frameworks (I've had so much fun with Spring proxy invocations over RPC), monkey patching and metaprogramming in dynamic languages (or as Zed Shaw referred to it in Ruby, chainsaw infanticide) ...looking at you Django...

I like it when I can read your code after you've moved onto another company and understand what the code is doing and why.

I've used "memoizing intermediate steps" often in the past, but it doesn't need to be magic.

Re:Dynamic programming in Haskell: automatic memoization by rowanG077 on Tuesday June 20, 2023 @09:17AM (#36403513)
The problem is that no one can define magic. The thing that you might find magic is someone else mundane code or vice versa. It's simply a catch all statement that a lazy reviewer can slap on code they don't like. Just explain why you don't like it and be done with it.
Re:Dynamic programming in Haskell: automatic memoization by EdwardDiego on Tuesday June 20, 2023 @09:25AM (#36403620)
That's a fair point, what's magic and what's a good abstraction is highly subjective.

I guess I'm a fan of the principle of least surprise.

I'd far rather explicitly define a configuration property in some file than "if you create an environment variable called FOO_CONFIG_X=5, the Foo framework will populate your settings for you!"

Because when the Foo framework doesn't respond to your incantations the way the docs say it should, then you're going to spend the rest of the day reading code to figure out why.

Shit, the Spring annotation magic made me miss XML context files for that reason, the XML made wiring explicit, as opposed to auto wiring annotations that failed deep in the bowels of the beast.

It's a continual problem across languages and frameworks, the (admittedly very) convenient magic is great until it isn't.

I've lost enough time on it in my career that these days the only dependency injection libraries I'll consider for a new project have to be compile time.

Still as much magic, possibly even more (trying to understand Quarkus' compile time DI library ArC is... something), but at least it breaks before you can deploy it.

Re:Dynamic programming in Haskell: automatic memoization by fho on Tuesday June 20, 2023 @08:51AM (#36403262)
I would also disagree with that, but maybe not as much as the other guy.

I had the pleasure of being able to use Haskell "in anger" for about a year. Still my favorite language to toy around with, but would not want to use it for work again.

One take away is that half of the time Haskell code "just works". You write algorithms as you think they should be and often the resulting binary is "good enough™".

The other half you spend in the trenches hunting down memory leaks because some thunk was not evaluated and your program is amassing unevaluater expressions until it dies :-)

Re:Dynamic programming in Haskell: automatic memoization by EdwardDiego on Tuesday June 20, 2023 @09:17AM (#36403511)
The other half is the magic that worries me ;)

And I'm not picking on Haskell here, I've lost countless hours to weird Spring failures when multiple annotations on one class or method interact poorly and produce a stack-trace deep in the bowels of Spring's annotation processors.

Or, well, gestures at Hibernate in general

Likewise, Django classes that defy type annotations because they override __new__ and inject nested classes into types, or queries over joins where the join logic between attribute A and type B is magically parsed from an undeclared keyword argument like "A__B__filter" that includes attributes, types and actions in one convenient keyword that no IDE can predict.

Like your unevaluated thunks, trying to figure out why "Foo__Bar__bomb_baghdad" didn't actually bomb Baghdad takes a large amount of time.

The magic is convenient until it breaks :)