Justified Programming — Reason Parameters That Answer “Why”

preview_player
Показать описание
Programmers usually bark commands at computers. Never does the computer ask “why”, and never does the programmer explain themselves. What if we did? Annotate the purpose of your function calls. It may save your day!

This is one of my few lessons that is not tied to any particular programming language. I do use C and C++ in these examples, but it would work just as well in nearly any other programming language.

Music:
- Tales of Phantasia :: Retaliation :: Motoi Sakuraba (converted into MIDI and played through OPL3 emulation through homebrew software)
- Famicom Tantei Club Part II: Ushiro ni Tatsu Shōjo :: Dean’s Room :: Kenji Yamamoto (SPC-OPL3 conversion)¹
- Onita Atsushi FMW :: Staff Roll (SPC-OPL3 conversion)

ERRATA
There is a typo in the strchr code shown at 1:20, my bad! The (~0ul - 1) should be just ~0ul. Coincidentally it does not cause the function to return incorrect values, it just tanks the performance. Without the bug, the dummied out code is 50% faster than the short code, but with the bug, it is 50% slower instead. Note that the SIMD-optimized assembler-coded strchr in glibc for x86_64 is still almost four times faster than the corrected code.
But there is also an actual bug in the strchr code on screen, that causes it to return incorrect values. Can you spot it?

#Bisqwit #Programming #ProgrammingPhilosophy #SelfDocumentingCode
Рекомендации по теме
Комментарии
Автор

"Programming consists mainly of labor to create a product. But programming is not just labor towards an end product. It is also labor towards making the labor itself easier." - Bisqwit.

A beautiful simple, and precise quote to demonstrate the realities programmers go through in life.

computerfis
Автор

I implemented something very much like this for a chatbot with a lot of modules. It had a kind of subsumption architecture where each module would be shown the input message in turn, and if a module thought it could handle the message, it would be the one to respond. This meant the output was sometimes very confusing and hard to debug. So I added a 'why' data structure that every module had to fill whenever they responded to a message. So then if the bot said something weird you could say "bot, why did you say that?" and it would reply using the contents of the 'why' data structure, like "You said 'what is the capital of england?', which seemed to be a geography question, so I asked Wolfram Alpha and it said 'London', so I said 'London' "

RobertMilesAI
Автор

Bisqwit, don't beat your Finnish accent up. I'm an American who quite likes Finnish culture, and I find the language particularly fascinating (hence my user name), and I'm sure many people feel the same. Great video as always.

ReagueOfRegends
Автор

Thank you for being my absolute favorite programming channel!

maxfortin
Автор

I have no clue what you are saying but i love your voice

hxveyyy
Автор

This channel is Gold. I’m so glad I found this. Thank you for making these videos. You inspire me. I hope you keep making more videos.

HusseinbergDude
Автор

Great video! As a novice programmer, I very much enjoy videos like these that are not so syntax heavy, but rather more conceptual or guideline focused. I hope to see more of this kind from you!

MrPixifan
Автор

Never been this early on one of your videos, wanted to say I love pretty much all types of videos you put out, keep up the good work :D

daan
Автор

This was very educational. I enjoyed the fun examples and exercises you used. I hope you make more of these videos.

GodofWar
Автор

Just laughed out loud at code comments at 1:03
It really is a window in the world of professional development.

gubx
Автор

Excellent tips for debugging code.
These tips should be in the book "Code Complete" due to how useful they are.
In most cases we do need to know not just how, but why.

jamesbalajan
Автор

Oh, please more of this. Coding patterns and best practices are totally intriguing to me. :-)

MrVankog
Автор

Totally off topic comment. Youtubers usually celebrate subscription count in decimal order. It would be cool to see you commemorating by powers of two. 65K, 128K subs. Or more precisely, 65.536, 131072 subs.

ricardo.mazeto
Автор

One drawback I've often seen in my own code is the state of mind one's into when writing the comment. Imagine you've been embedded into coding for weeks and you comment something in such a way that it looks perfectly clear, because you understand the context (which may span across many source files). Then you quit the code for months to work on something else and when you come back, the comment is anything but clear. It actually seems to make no sense at all! ^_^

DamianReloaded
Автор

idk who this guy is, i dont even know why im watching this, but this has such high production value! subscribed

EnderCrypt
Автор

Great video as always Bisqwit! As others have said I like your accent. Your English has always been very good and clear.
Anyway, this gives me a video to help my friends "get it" when it comes to the why of programming.

PixelOutlaw
Автор

Really useful tip. More of these please!

yoloop
Автор

seems like a legit paradigm to better counter upcoming errors! Thanks!

rcookie
Автор

A little late to the discussion but I wanted to add a useful pattern here is to create a set of reasons why you're program might change state and declare them as a set of extern const char pointers). When the state changes, you pass this parameter. That way you can better predict and control the size of the compiled binary since string literals can get out of hand/overused in larger projects. I observe that Python and Go have this pattern (using error libraries) and C/C++ would benefit from the user doing that kind of work. As always, great paradigm, cheers Bisqwit!

samiurkhan
Автор

Many people have this innate repulsion against personalizing computer code (with the notable exception of printf() and comments) as if they think human traces don't belong in computer code or that mere strings will somehow affect code performance.

Fantastic video by the way!

ihato