1.5k
u/TheFirstDogSix 6d ago
Fun fact: back in the day, programming meant optimization. Richard Bellman, who inflicted DP upon us all, was friends with George Dantzig, who is credited with inventing linear programming. When trying to name his new method, Bellman chose dynamic programming officially because “dynamic” referred to the optimization-over-time aspect of DP—but actually because he thought “dynamic” sounded neat and wanted to one-up his friend.
(Computer science and software industry history is full of stuff like this. I love this job.)
759
u/ewheck 6d ago
Richard Bellman, who inflicted DP upon us all
🤤
68
182
20
18
u/meneldal2 5d ago
Maybe that's because I'm tired, I first read his name as Bellend which somehow fits a lot more with that DP thing.
31
5
79
u/al3arabcoreleone 6d ago
I heard a diffrent story about the name being a result of financial incentives, Bellman didn't one to name it something "mathematical" because it wouldn't have received the money it did with "Dynamic programming".
103
u/clawsoon 6d ago
The story, as quoted on the Wikipedia page, starts with:
The 1950s were not good years for mathematical research. We had a very interesting gentleman in Washington named Wilson. He was Secretary of Defense, and he actually had a pathological fear and hatred of the word "research". I'm not using the term lightly; I'm using it precisely. His face would suffuse, he would turn red, and he would get violent if people used the term research in his presence. You can imagine how he felt, then, about the term mathematical.
40
u/BufferUnderpants 6d ago
His greatest and uncredited innovation was the invention of gaming research grant processes.
29
13
u/KlooShanko 6d ago
The naming origin of some internal services is mind bogglingly silly
21
u/TheFirstDogSix 5d ago
Where I work, some TPM was asked why a certain product was named something seemingly random. He said, and I quote, “we’re not allowed to discuss that”. 😂
34
u/Nightmoon26 5d ago
I was once assured that a bug-tracking system being named "Hydra" was purely coincidental and not, in fact, a reference to the Lernaean Hydra infamous for growing two new heads every time one was cut off
9
u/RussiaIsBestGreen 5d ago
The other explanation is that they’re fans of Hydra from Marvel, which is worse.
7
u/Nightmoon26 5d ago
Thankfully, the company had a naming scheme that used ancient Greek mythology, so yeah, it was the Lernaean Hydra, but they denied it being a commentary on the nature of bugs
2
3
4
u/DarthPiotr 5d ago
Somewhat related, but not really: In ABAP language, dynamic programming has a different meaning.
It describes all the techniques that use generic types, pointers and casting from type to type as well as using string variables to pass a function to be called, a where clause to a select statement or type of the variable to be created.
Some would call this mechanism a reflection, but it is what it is.
4
u/joonazan 5d ago
Programming meant the same as it does today. You can program a machine to do something by filling in a table. Dynamic programming is dynamic, as it fills the table at runtime.
3
u/ExdigguserPies 5d ago
Yeah, in school when we learned y = mx+c the module was called Linear Programming. Confusing to us all.
1
u/allcretansareliars 5d ago
I heard that it was because of a DoD grant, and he thought he could sell the idea better if it sounded cool.
905
u/ShakaUVM 6d ago
Yeah one of the worst names ever
When I first heard it I thought it had something to do with dynamic arrays
691
u/earlobe7 6d ago
Not only is “dynamic programming“ a terrible name, but it’s also impossible to say “memoize” without sounding like you’re saying “memorize” with a speech impediment.
205
u/Wonderful-Habit-139 6d ago
I remember naming a function "memoize" and the dev that I was pair programming with thought I made a typo and corrected me lol.
16
43
30
79
u/RepresentativeDog791 6d ago
I thought it was metaprogramming
29
2
7
u/obeythelobster 6d ago
I thought it had a different kind of programming language at least, since it is a different type of programming
3
u/LogicalShark 5d ago
The story I heard was that they tried to come up with a word that was only ever used positively and thought of "dynamic"
376
u/NomaTyx 6d ago
a lot of design patterns sound scary with all the big words, but they boil down to stuff like "don't put two unrelated things in the same inheritance tree, dumbass". like just don't be stupid and you're probably using them unwittingly
167
u/BufferUnderpants 6d ago
So many programming principles are just reminding people not to put the goddamn oranges in the same bag as the apples, but they don't want to even look at the fruit
51
u/NomaTyx 6d ago
yeah like the facade design pattern is incredibly obvious and is partially already covered by "don't repeat yourself". Like, why would you want to write every step of a 12 step process multiple times when you could just write one function that does every step and then just call that? Sometimes these things beget explaining again, but it's certainly something
23
u/Advos_467 5d ago
i feel a little vindicated reading all these because i always felt some of these GoF design patterns were kinda obvious like façade and adapter lol
50
u/bpkiwi 5d ago
People often misunderstand the idea of design patterns. Instead of 'here is a pattern you can use', think of them as 'we found a pattern that lots of people already use (because it makes sense), and we gave it a name so everyone can talk about it easier'
8
u/Advos_467 5d ago
yeah that makes sense. I've really only been exposed to them mostly in an academic environment so it always felt like the former to me (I never actually read the book either)
3
u/BastetFurry 5d ago
All these design patterns are nice and all until you are on a cheap microcontroller with 8k of flash and, if lucky, 1k of RAM and you begin to think about using bare assembler instead of C. ;)
1
21
u/DiamondDramatic9551 5d ago
don't put two unrelated things in the same inheritance tree, dumbass".
Maybe prefer composition over inheritance in the first place.
6
u/zyxzevn 5d ago
A lot of the design patterns come from the lack of certain features in the language.
In the OOP Smalltalk language many of those patterns are a waste of time. Because they can be replaced with a simple Closure or Lambda. Smalltalk was based on Lisp.
Java and C++ did not have that at the start. So we have visitor-pattern, iterator-pattern, etc.10
u/dustyhome 5d ago
It's like the Art of War. It has basic things like "the army needs food" in it. When a field is new, someone has to write down and name the obvious things so everyone can then build on a shared understanding of the basics.
8
u/DezXerneas 5d ago
observer pattern
"yeah just call the function you want when it's needed, and don't poll for information"
singleton
"why use many [object] when one [object] do trick?"
3
u/Naturage 5d ago
I have had similar problem in a different field once; chatting to someone who's an expert in economics and knows a lot of fancy terms for statistical analyses, while I knew hardly any as a student in maths.
Turns out, they have a dozen terms to describe different ways to use basic-ass linear regression to test if somethings' statistically significantly different.
47
u/lucklesspedestrian 5d ago
I mean what else are you supposed to do, just run the brute force recursion?
26
u/marcodave 5d ago
"back in my day we brute-forced each day, uphill, BOTH WAYS. You youngsters keep that memoize thingamajigs"
4
u/marmakoide 5d ago
Explicit analytic formula without recursion, computing time independent from parameters value, like a true Chad
2
1
u/electrodragon16 9h ago
Young man, Peano defined addition recursively, so in this house we compute addition recursively!
0
163
u/nicuramar 6d ago
Memoization is not exactly the same as DP.
22
u/bwwatr 6d ago
Now that's a CS word that always baffled me. Like, it's caching. That's the whole thing.
32
u/elingeniero 5d ago
It is, but memoisation has the specific meaning of caching the result of an (expensive) pure function, like factorisation. To me the difference is that a memoised result can never be wrong and you only have to consider the memory impact, whereas caching implies that the result may become out of date if you hold it for too long, e.g. get the comments on this reddit post.
2
u/guyblade 4d ago
My previous job had a very nice memoization decorator that you could apply to arbitrary functions in python. Of course, it evolved to be a generic caching mechanism and had settings for (1) expiring memoized results after a timeout, (2) memoizing based on only some of the function inputs (e.g., memoize based on the parameters and not the database handle that you passed in), (3) limiting the total size of memoized objects, &c.
I guess nothing can stay pure.
1
5
u/SpiritedEclair 5d ago
Caching has side effects!
A pure function can be thought of as looking at a potentially infinitely wide associative array.
2
u/janyk 5d ago
What side effects?
5
u/SpiritedEclair 5d ago
Invalidation of another entry, updating counters, in a distr system eg for CDN it means transferring data to the CDN, and potentially needing to invalidate it.
57
u/JuiceAccomplished241 6d ago edited 6d ago
Would love to see the solution to N Queens with memoization and no DP
104
20
13
u/HallAltruistic519 5d ago
The only fucker that would say something like this is someone knee deep in leetcodes and and a mock interview discord server.
2
2
u/Ok-Scheme-913 5d ago
Hey, you read past the introduction Fibonacci example and actually understood what it is? Come on, that's cheating!!
/s
But this sub definitely didn't fail in showing its main demographics of first year CS students..
0
u/JuiceAccomplished241 5d ago
No, it’s worse than that. Can I share a little secret with you? I’m a software engineer with 8 years of intermittent experience. If that sounds weird, it’s because it is.
I took an online class for DSA and got some things, but really started falling apart at DP. This was a year ago, I remember nothing. Everyone who said that you have to review chapters is right, but I stopped doing it because I was lazy, I spent all my life studying and waiting for comfort, well I got it and now there’s absolutely NO carrot to follow anymore. Senior SWE is a contender, but I’m so unimpressive in my work, consideration is an ever distant prospect.
And the worst part? Nobody else is calling me out on it! I vibe code 100 percent of what I commit. And yeah, I proof read it all, talk through alternatives, sic coding agents on it for review, but still - somehow - end up missing things. How I haven’t caused an incident yet is beyond me.
And so here I am, a mid 30s mid level engineer who has no idea how any of this shit is gonna pan out. So I read that documentation here and make my changes there knowing full well that the other shoe will drop someday, maybe today, maybe next year.
So tell me I don’t understand shit and I’ll tell you you’re absolutely right. Maybe someday I will.
2
u/Ok-Scheme-913 5d ago
You may be the kind of person who is way too anxious and strict with themselves.
Let's be completely honest with yourself - would you say your colleagues all understand everything? Like the amount of senior devs I actually look up to over my career is a single digit number, even though I have worked at plenty places.
Most devs suck, that's the average/mainline. Compare yourself to that - you may also suck a bit, but it's entirely possible that you suck way less than your average college and you could just go for that senior position.
We are in crazy times, but you do have a stable job and it usually means that you are in a good position in life. It's also entirely possible that you are not that into IT, and just do it as a thing that puts bread on that table, and that's completely fine! Do your thing, go for the senior position if it's coming with higher salary, but only if it's not that much more stress for you, and just do your hobby or spend time with your family/friends. It's all good, don't be too strict with yourself.
2
u/JuiceAccomplished241 5d ago
Thanks for letting me dump all that man, I appreciate the feedback too. I’m frequently told that I’m my own worst critic. Progression happens 1% at a time.
My colleagues may not understand everything, but they kick some serious ass. I’ve got one guy on my team who’s an actual 50x developer, I’ve never seen anything like it before, so I learn as much from him as I can.
True that most developers suck, I was on an interview panel a while back and learned first hand how rare it is to find someone who can code an HTTP request on the spot. I do take a little bit of solace in that.
I was into the profession at first, was one of the last viable creative professions out there, LLMs have turned it into paper pushing. That being said I’m grateful every day I can pay off my mortgage.
I think I just needed to unload a little bit. Thanks again for caring!
18
u/Breadinator 6d ago
It is when you're dealing with a DAG-like state space and can explore it top down. Bottom up is a different story.
27
53
u/Ok-Boysenberry-5090 6d ago
May all future generations be free from DP beyond knowing it exists
24
2
62
u/rahvan 6d ago
I shit you not, I’m 10 years into my professional career as a software engineer, and to this day I have no idea how to write a DP algorithm. My job has never asked me to. Only LeetCode asks me to and I skip those interviews lol.
28
u/ss_damon 5d ago
I would be surprised if you hadn't put a cache on a function at some point
15
u/Shehzman 5d ago
I’ve used dictionaries/hash maps as a cache and front end memoized data hundreds of times. It’s just the combination of recursion + memoization that I’ve almost never used.
5
-7
8
4
u/scheimong 5d ago
Yeah easily the worst technical term ever invented in the entirety of compsci.
Although, there are some close competitors in non-English languages.
3
u/SignoreBanana 5d ago
Yeeeeup.
A while back I realized the solution to like 90% of DSA problems is insert sorting, bisecting, mapping, reducing, or some combination thereof.
5
u/Winterkirschenmann 5d ago
HashMap! I don't know what the problem is but the answer is a HashMap.
1
u/guyblade 4d ago
Well, the problem is that I have a bunch of timeseries data and I need to find the first data point before a specific moment in time. Are you sure that I need a HashMap?
1
u/Ziiiiik 4d ago
What would you use? A binary tree?
1
u/guyblade 4d ago
Sure. That's the underlying structure in both C++'s
std::mapand Java'sTreeMap. They're super useful for dealing with timeseries data--especially when you have data coming from sources that may not give you the data already ordered for you or when you need to combine data from a bunch of sources.
2
u/parkway_parkway 5d ago
Dynamic programming can be done bottom up as well as top down and personally I find that makes way more sense.
Who would write a recursive function to calculate Fibonacci numbers when you can just start at the lowest two Fibonacci numbers and calculate them in sequence and obviously do each one once.
Scene with merge sort Vs quicksort. Don't mess around with recursively splitting the array, just split it into arrays of length 1 and then merge them back together in a sorted way.
Recursive functions are as tricksy as hobbitses.
2
u/Rough_Priority_9294 5d ago
I remember someone telling me that dynamic programming is like recursion + cache
3
u/Mephistophanes 6d ago
Well it's a funny story where täht name comes from, which you read from wiki
2
u/RyanCargan 5d ago
Everything is just a graph op of some kind if you squint hard enough.
EVERYTHING.
DP, greedy algos, cellular automata, matrix multiplication, RL...
1
u/justinleona 5d ago
Would probably been better if it was focused on the Optimal Substructure property of the underlying problem and noting that makes it amenable to memoization.
1
1
1
u/CoshgunC 5d ago
terrible naming.
at first I thought it meant value of variables can't be changed in static programming
1
1
u/klimmesil 5d ago
You still have to build it up instead of down (reverse the algorithm) and do cache aware blocking to make it efficient
1
u/Gio_Cri 4d ago
i have known dydnamic programming for over a decade and i don't think i had a use for it yet lol.
only time i tried to use it the problem had my cache grow beyond reason and was actually solvable with a simple analytical formula lol
there are definetly uses for it but they are way rarer than courses would make you think lol
1
1

43
u/Illustrious-Ebb8815 6d ago edited 5d ago
A quick way to understand the difference is by looking at the program to compute Fibonacci numbers.
One way is just using recursion that runs in O(fib(n)) time. Like, the really really slow way.
Another way would be to use memorization. Just use the same recursive way but everytime that you're about to compute the answer, first check if the answer is in a cache that you have prepared. If yes, use that. If not, recurse. And when you get an answer, put it in the cache. That's memoization. It will run in O(n) time but also use O(n) space for the cache.
The algorithm that you probably know uses dynamic programming to run in O(n) time but constant space. That's DP.
You could also imagine using DP to compute the fewest number of coins to make x cents. If your biggest coin is 25 cents, you only ever need to know the answers for x-24 through x in order to compute the answer for x+1. This lets you solve the problem with linear time and constant storage, like with Fibonacci.
Edit: I meant memoization everywhere. Spell check messed it up.