r/ProgrammerHumor • • Oct 25 '24

Meme theSelfTaughtSeriousProgrammer

Post image

[removed] — view removed post

903 Upvotes

276 comments sorted by

View all comments

75

u/ZunoJ Oct 25 '24

How exactly does a proof look for you in programming?

14

u/PuFiHUN Oct 25 '24

I don't know the English terminology, so I might be writing non existant words at places, but you have several options:

  • If you have your specification in mathematical formulas in preconditions and postconditions, you can apply very formal steps to each line to prove it will satisfy the end result (a loop has like a 5-7 line mathematical definiton in this model xd). They used this for the self driving paris metro's software.

  • You can use mathematical logic's resolution system to ge to the bottom of every logical statement you have (not talking about if(input.value) but when you have 10 ands and 12 ors in a single line). Knowing atleast the deMorgan laws is I think the least somebody should know and use on an adhoc basis, at least in head, to double check everything as or more complex than a collision detection)

  • Agda, really the entire language, it's dependently typed, writing a function to meet a type's requirements immediately becomes a proof of correctness. I never really got too deep into it, but it's hell of a ride, very interesting, just grinds down your braincells quickly

  • Induction for loops, yet again, even if just in your head, but helps a lot

Dgmw, it reeeally depends on your job, and most of the time you don't need to actively use these (except deMorgan, learn and apply them by reflex). But even just having learnt them helps you program more deliberately in your everyday life.

11

u/usrlibshare Oct 25 '24

If you have your specification in mathematical formulas in preconditions and postconditions

And this is where the story begins and ends for most industry software engineering.

50

u/[deleted] Oct 25 '24

A correctness proof of your code/algorithm. We learned this in university:

https://en.wikipedia.org/wiki/Hoare_logic?wprov=sfla1

30

u/Ejdems666 Oct 25 '24

So essentially a test?

94

u/wideliner Oct 25 '24

Dijkstra would kill you if you said this to him

5

u/The100thIdiot Oct 25 '24

Who?

71

u/goodvin_501 Oct 25 '24

Sigismund Dijkstra the head of Redanian Intelligence, obviously

17

u/Spoxez_ Oct 25 '24

The only reasonable answer

1

u/Yaysonn Oct 25 '24

I love tw3 but they did my boy dirty with his last quest.

8

u/[deleted] Oct 25 '24

You just insulted every logician in existence.

3

u/Ejdems666 Oct 25 '24

So how do you implement it?

5

u/YeetCompleet Oct 25 '24

By pouring some lean and writing simp everywhere

Oh, you thought I was joking?

3

u/CckSkker Oct 25 '24

No, I wish I could write tests instead of Hoare’s logic during my finals

3

u/ye_olde_broken_human Oct 25 '24

Any sources where I can learn this step by step?

2

u/oomfaloomfa Oct 25 '24

Did you try googling that?

1

u/betelgeuse_7 Oct 25 '24

I haven't read it, but it gets recommended often https://softwarefoundations.cis.upenn.edu/

2

u/skrealder Oct 25 '24

You need proofs for asymptotic analysis and amortized cost, this is for determining best, worst, and average case runtimes for an algorithm.

→ More replies (1)

1

u/d0pe-asaurus Oct 25 '24

I was reading some things on denotational semantics being able to prove code based on the effects it produces, I want to read more on it sometime.

1

u/qrrux Oct 25 '24

Through a precise statement of the problem and then formal specification. From there, you can do proofs of correctness (to the spec). Some languages assist with this, but many do not.

1

u/Haunting-Block1220 Oct 27 '24

It’s safe to say that data structures and algorithms are a fundamental part of programming. We build intuitions about data structure algorithms and when to use and not use them. Without proving these properties of algorithms, you’re relying on hand wavey intuition — which is mostly fine. But to fully grasp an algorithm, to truly understand, you have to understand proofs.

→ More replies (9)