Тёмный

Justified Programming - Reason Parameters That Answer “Why” 

Bisqwit
Подписаться 147 тыс.
Просмотров 63 тыс.
50% 1

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.
Twitter: / realbisqwit
Liberapay: liberapay.com/Bisqwit (alternatives at iki.fi/bisqwit/donate.html)
Twitch: / realbisqwit
Homepage: iki.fi/bisqwit/
You can contribute subtitles/captions at: ru-vid.com_vid... Or to any video on my channel at:
ru-vid.com_cs_...
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)
¹) This is probably an adaptation from a concert/fugue/toccata/something by Bach. If you are someone who knows classical music and you recognize this song, please clarify this in the comments! You can listen to the full song at: • Video
The first song can be listened here: • Retaliation (ToP) SPC-...
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

Опубликовано:

 

25 июл 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 218   
@computerfis
@computerfis 6 лет назад
"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.
@tomyyoung2624
@tomyyoung2624 Год назад
yes cest de la scrap
@RobertMilesAI
@RobertMilesAI 7 лет назад
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' "
@Bisqwit
@Bisqwit 7 лет назад
The exciting thing about neural network based AIs today is that they are totally _incapable_ of providing justifications for their decisions, much like little children (at least until they think hard enough). It’s all basically a number soup from which a decision emerges somehow.
@RobertMilesAI
@RobertMilesAI 7 лет назад
Yeah! In this way they're really the same as the vast majority of the brain as well. If you find a bug in your visual cortex (like an optical illusion), you can't ask it "Why did you decide these parallel lines are sloping towards each other?" (upload.wikimedia.org/wikipedia/commons/thumb/d/d2/Caf%C3%A9_wall.svg/1200px-Caf%C3%A9_wall.svg.png), the neural network is just a 'black box'. But there's some interesting work being done on making the artificial ones more legible. I think it's pretty important for safety reasons to be able to understand why a neural net behaves as it does, maybe I'll cover some of that research for my AI Safety channel :)
@animowany111
@animowany111 7 лет назад
+Robert Miles There is a lot of research put into visualizing neural nets. Do you remember Google DeepDream? That is an attempt at visualization. It adapts the input to maximize the activation of a single neuron, or a group of neurons, so you see that one neuron detects eyes, another neuron detects trees, and some other neuron detects windows. As a side effect, it produces images from an LSD trip.
@computerfis
@computerfis 6 лет назад
It is really an exciting age to be a part of (:
@josealvim1556
@josealvim1556 6 лет назад
Oh, I wondered why I recognised your name! Your videos about AI in computerphile always peaked my interest. I had no idea you had a channel of your own, good to know :D
@ReagueOfRegends
@ReagueOfRegends 7 лет назад
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.
@maxfortin9211
@maxfortin9211 7 лет назад
Thank you for being my absolute favorite programming channel!
@MrVankog
@MrVankog 7 лет назад
Max Fortin Do you have suggestions for any others? I really like the sessions from Coding Train (formerly known Coding Rainbow). The guy is amazing and I love the concept.
@maxfortin9211
@maxfortin9211 7 лет назад
MrVankog Computerphile. All the way. It's a little more theoretical but it's honestly awesome. Cherno also does a well done tutorial on c plus plus and other languages.
@MrVankog
@MrVankog 7 лет назад
Max Fortin Computerphile, how could I forget ^^ Yeah, but often times the videos over there are not what I'm expecting of it. Too often it's only a history lesson or an interview or philosophical questions (sometimes interesting, sometimes not). And if interesting stuff is shown, it's often not deep enough for me. Mostly it's just a shallow overview of a topic. So generally they are aiming for people who are new to programming and information science and thus are mostly not nerdy enough for me. ^^ On the other side of the spectrum there is Bisqwit who is so deep in the field that I often just plain out. *g
@jamesbalajan3850
@jamesbalajan3850 6 лет назад
+MrVankog If you like graphics programming, which Bisqwit does a lot check out Hopson. He even uses a similar soundtrack.
@ricardo.mazeto
@ricardo.mazeto 7 лет назад
Totally off topic comment. RU-vidrs 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.
@Bisqwit
@Bisqwit 7 лет назад
I considered 32768, 33333, and other such numbers, but it’s been such a silly ride with daily view & subscription counts varying as much as by a factor of 100 from a day to the next, thanks to RU-vid algorithms, that I haven’t even had time to make a video that wouldn’t be pointless by the time it’s ready. Incidentally it has made it almost impossible to use RU-vid analytics to profile what works (in terms of SEO) and what does not, because there are no patterns, at all. If you are interested, you can check out socialblade.com/youtube/user/bisqwit/monthly and look at the graphs to see what I am talking about.
@hxveyyy5521
@hxveyyy5521 7 лет назад
I have no clue what you are saying but i love your voice
@GodofWar1515
@GodofWar1515 5 лет назад
This was very educational. I enjoyed the fun examples and exercises you used. I hope you make more of these videos.
@marcusterrel1686
@marcusterrel1686 3 года назад
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.
@MrPixifan
@MrPixifan 6 лет назад
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!
@MrVankog
@MrVankog 7 лет назад
Oh, please more of this. Coding patterns and best practices are totally intriguing to me. :-)
@daan6995
@daan6995 7 лет назад
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
@DamianReloaded
@DamianReloaded 7 лет назад
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! ^_^
@ETXAlienRobot201
@ETXAlienRobot201 6 лет назад
Or when there are no comments! XD
@r1pfake521
@r1pfake521 5 лет назад
Or when the comment is wrong and you try to understand how the code is supposed to do what the comment states until you give up / realize that the comment is just wrong
@VivekYadav-ds8oz
@VivekYadav-ds8oz 5 лет назад
Yep. That's happened to me multiple times and I hate it XD.
@tomyyoung2624
@tomyyoung2624 Год назад
yes making any sense whatsoever.
@jamesbalajan3850
@jamesbalajan3850 7 лет назад
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.
@PixelOutlaw
@PixelOutlaw 7 лет назад
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.
@greob
@greob 7 лет назад
The amount of work put in this video is impressive. Thanks!
@gubx42
@gubx42 7 лет назад
Just laughed out loud at code comments at 1:03 It really is a window in the world of professional development.
@TBasianeyes
@TBasianeyes 7 лет назад
The one at 1:20 got me.
@ihato8535
@ihato8535 7 лет назад
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!
@twiksify
@twiksify 7 лет назад
Nice work, this reminds me of how an AI decision tree can be used to describe why each step is issued. For example if you ask the AI of a car to drive from A to B the steps might be ReleaseHandbreak-SetGearboxToNeutral-StartEngine-SetGearboxToDrive-ApplyGas-DriveToB-StopEnigine-ApplyHandbreak. You might ask the question why did you set the gearbox to drive and the decision tree will reply because I needed to apply gas.
@rcookie5128
@rcookie5128 7 лет назад
seems like a legit paradigm to better counter upcoming errors! Thanks!
@yoloop93
@yoloop93 7 лет назад
Really useful tip. More of these please!
@doriphor
@doriphor 7 лет назад
Looking forward to your next livestream! I hope it happens soon :)
@Bisqwit
@Bisqwit 7 лет назад
Me too! Thank you.
@samiurkhan
@samiurkhan Год назад
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!
@ZLau13
@ZLau13 7 лет назад
For once a Bisqwit video I understand. I should appreciate documentation more but often what I do (demoscene) just requires visible results as soon as possible and the product only needs to run once for the compo :D
@j5679
@j5679 7 лет назад
Please note that all shown mutex examples generate undefined behavior. Locking a mutex multiple times from the same thread without unlocking is UB. std::recursive_mutex would solve this problem in this case. Furthermore, instead of manually locking and unlocking, I'd suggest using std::lock_guard to fully make use of RAII. It also makes sure that the mutex is unlocked even if an exception is thrown between .lock() and .unlock().
@Bisqwit
@Bisqwit 7 лет назад
I totally agree about std::lock_guard and RAII. The reason I did not use that was the line number count: I didn’t want to need to shrink the font to fit more lines on screen. And as for std::recursive_mutex, it would not have evoked the deadlock effect, and that would have foiled the lesson. And while nested locking is undefined for std::mutex, it does result in a predictable deadlock on all platforms I have used it on, and trying to craft a lesson around the same effect without undefined behavior would have needlessly complicated this lesson with irrelevantities. To make sense of this, consider that the “std::mutex” on the screen is just a placeholder for a platform-specific non-standard mutex object. There _is_ no std::recursive_mutex or std::lock_guard for this platform unless you make them yourself. I used std-objects in the example code for brevity and for the ease of getting the point across. In any case, thank you for your input.
@EnderCrypt
@EnderCrypt 7 лет назад
idk who this guy is, i dont even know why im watching this, but this has such high production value! subscribed
@Norhther
@Norhther 7 лет назад
Really cool! I want more of those kind of videos
@MrBrax
@MrBrax 3 года назад
this saved me in my most recent program, good thing i remembered this tip
@moji8225
@moji8225 6 лет назад
Kudos for your efforts...just perfect ! thanks
@ToTheEntropy
@ToTheEntropy 7 лет назад
A great thing to add to our daily code, i'm sure of it, and never through about something like that, thank you for the idea! But after thinking about it another W add to the What and the Why come to my mind, it's the When. What do you think is the beast approach to set it? Before creating the function? When we have something that "work"? At another time? How do you set it yourself when you use it?
@MinimumOverkill
@MinimumOverkill 7 лет назад
Very cool technique, I don't do this too often but adding extra context parameters to your functions is a fairly solid solution for finding bugs. For debugging this is admittedly it's a lot less time-consuming than doing hex address math on paper, or doing blind breakpoint bisection until finding the bug. I will say though, I think if you do this sort of diagnostic in a hot path of your code in a performance-demanding program like a game or audio mixer, you may want to consider only using const char* or std::string_view (if you're in C++14 or later world), since that will avoid potentially-costly std::string(const char*) construction that can add up as you pass string literals as const std::string& parameters, and this will slightly delay the costs of passing around extra context until the parameters are actually used, while keeping copies off of the normal/success path. Alternatively, maybe having this context parameter behind a #define, so it is discarded unless running in debug or optimized-but-extra-diagnostics executables, would be another way to go. Another way I like is to assert on a failure condition, and use a debugger to break at the failed assertion point. The context is in the stackframe that caused the assertion, and then you can inspect the locals and call stack. This is pretty common to use via assert() or some other similar forced-breakpoint constructs like "__asm int 3" (on x86) etc, but maybe someone out there could use the reminder, as opposed to using printf. The downside to the raw assert method is typically the program aborts after the assert so you can't resume further, and even if you could resume (in the case of __asm int 3 / __debugbreak() / etc) it interrupts the flow of the program if you want to capture some timing-sensitive info multiple times without constant debugger pauses. Also, it mandates having a debugger, whereas the added-context method allows you to potentially share builds with other people and collect logs of all the failures later. I can see the value in that for long-running applications like games, emulators or network applications.
@frogofdeparture
@frogofdeparture 5 лет назад
Would it be possible to isolate these reason parameters to debug builds with some template/preprocessor/build system magic? More importantly, could it be done practically?
@per-axelskogsberg3861
@per-axelskogsberg3861 7 лет назад
This was actually really interesting and helpful. It is going to make collaboration alot easier. Thanks.
@sickysore
@sickysore 7 лет назад
thank you, your channel is amazing
@tomyyoung2624
@tomyyoung2624 Год назад
Yes I have yes!
@r3ap3rpy
@r3ap3rpy 5 лет назад
Awesome video, excellent explanation.
@The1wsx10
@The1wsx10 4 года назад
that strchr function looks like one that would benefit from micro optimization, since its the type of function that would be called a lot from many different places
@Lak3
@Lak3 7 лет назад
Great video, once again =)
@jarrad2000
@jarrad2000 7 лет назад
Nice idea! BTW: did you take a look at blender as a video editor yet?
@Bisqwit
@Bisqwit 7 лет назад
No, I have not.
@AkamiChannel
@AkamiChannel 5 лет назад
Your videos make me happy.
@Bisqwit
@Bisqwit 5 лет назад
Glad to hear that!
@MegaHalobro
@MegaHalobro 6 лет назад
hey joel, I program on windows 10 using an intel i5 with my code compiled with a recent minGw32 version(I fully installed the complete version in august) and using SDL2, will any code you have posted compile for me, I want to use your code to help me exercise my c++ knowledge, but as long as I can execute it
@Tinfoilpain
@Tinfoilpain 7 лет назад
Also you can use clang's -fsanitize=thread to catch any possible race conditions. It's very impressive.
@Bisqwit
@Bisqwit 7 лет назад
On platforms where it is available.
@MrHack4never
@MrHack4never 7 лет назад
Why do some programmers use signed int's in situations where the numbers only will go positive? e.g. runtime, counters, etc.
@Bisqwit
@Bisqwit 7 лет назад
That’s a good question. Maybe ‘int’ is considered a general purpose type suitable for counting and such and ‘unsigned’ is too pedantic. This is not my view, I do use unsigneds whenever I don’t explicitly need signed values, but I imagine that is how people think. It is worth noting that the code shown at 0:57 is not mine; it is copied¹ from a well-known open-source project from the late 1980s. ¹) With minimal changes; the original code is K&R.
@lolisamurai
@lolisamurai 7 лет назад
sometimes you need to pass around integers between functions that accept signed and you don't wanna be casting it or suppressing warnings, or maybe you will compare those integers to a signed integer later on. it's also pretty common to make stuff return negative values for errors and the result as a positive value for success. because of these reasons, I often end up making everything signed just in case. it's ultimately preference
@guilhermealveslopes
@guilhermealveslopes 4 года назад
Reason parameters are amazing, instead of having the why in design only, we have the why inside the code itself!!!
@greatwhite6619
@greatwhite6619 7 лет назад
Me: *Adds why parameters to all functions.* co-worker: WTF WHAT THE HELL HAVE YOU DONE ARE YOU OUT OF YOUR FUCKING MIND?!?!? AHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
@sznio
@sznio 7 лет назад
Can this be feasibly implemented in the real world scenarios? The mutex example is a really good usage of this paradigm, I once ended up actually creating something like this when debugging a deadlock on a platform that didn't support pthreads (on Linux or other pthread platform, such deadlock as illustrated will immediately fault and let you know that you attempted to lock a mutex twice in the same thread). I think that forcing a programmer to explain themselves on every state change will cause them to ~~slowly descend into madness~~ stop paying attention to them and write "foo" in each one. This could be a feasible feature, if a programming language implemented it as a core feature, not tacking it onto already oversized C++.
@victorfds
@victorfds 3 года назад
Excelente vídeo!
@darkkevinyou
@darkkevinyou 6 лет назад
Is this the bug mentioned in the errata? "The terminating null byte is considered part of the string, so that if c is specified as '\0', these functions return a pointer to the terminator." - strchr(3)
@Bisqwit
@Bisqwit 6 лет назад
Yes, that is correct.
@justanormalperson
@justanormalperson 7 лет назад
why would i myself bark commands at a computer? i can make a program to automate that so i don't have to
@Fellintr
@Fellintr 2 года назад
Now, I usually hate when people tell me how I should program. But this is actually a good idea!
@jamesbalajan3850
@jamesbalajan3850 6 лет назад
Cool alternative to standard unit testing. I have couple of questions though Bisqwit. When you create production level code for a company do you follow clean code design methodology do you use macros, and do you use justified programming? Another question I have, which may be a little bit tedious because you have probably heard this before, yet I am curious as to when your next educational video will be released. And, as a final question, can we connect on LinkedIn as professionals?
@Bisqwit
@Bisqwit 6 лет назад
1) I only use the principle of this video for particular situations where it is warranted. 2) Should be coming actually within a week or so; it is being rendered right now. 3) I rather infrequently approve (some of) requests I receive on LinkedIn.
@jamesbalajan3850
@jamesbalajan3850 6 лет назад
Thanks for the reply
@Vextrove
@Vextrove 2 года назад
That is most definitely a Bach piece, although I don't remember its BWV number. I believe it may be a movement of one of the French/English/Italian suites, due to the way it is structured and certain musical elements used in the piece. It is definitely a keyboard piece though.
@Bisqwit
@Bisqwit 2 года назад
I later found that it is Bach's Invention No. 15. Thanks for commenting!
@tomyyoung2624
@tomyyoung2624 Год назад
@@Bisqwit Yes a djinn,
@AlwaysTeachingable
@AlwaysTeachingable 7 лет назад
Bisqwit today I was a little bit worried about my bad documentation habits and there it goes ! A great video that helps me make better documentation, are you a djinn? :^) P.S keep doing what you love bisqwit I really appreciate your hard work
@Bisqwit
@Bisqwit 7 лет назад
Not a djinn, nor any other creature from the tales of 1000 and 1 nights. Just pure statistics :-) Thank you for commenting!
@typedef_
@typedef_ 7 лет назад
I was just about to ask "why" you locked in both WriteByte and WriteBytes haha. Cool.
@Bisqwit
@Bisqwit 7 лет назад
Both are user-callable functions, that’s why. But it is difficult to hide an “elusive” bug for education purposes in 50 lines of code that are all in plain sight, so forgive me if it seems silly. :-)
@ThreevanGH
@ThreevanGH 6 лет назад
The classical piece is Bach's Invention No. 15.
@Bisqwit
@Bisqwit 6 лет назад
Thank you!
@LukasanaTK
@LukasanaTK 6 лет назад
Bisqwit did you ever try object pascal, if yes what do you think about Modern Object Pascal compared to C++?
@Bisqwit
@Bisqwit 6 лет назад
I used to program in Turbo / Borland Pascal before I began learning C++. Delphi (Object Pascal) is mostly derived from Borland Pascal. I enjoyed it a lot, but C++ is better. I haven’t been keeping tabs on how Pascal has been doing in the last two decades.
@Shadlock0133
@Shadlock0133 7 лет назад
Don't know if you checked it, but Rust has something similar builtin into standard library with Result and Option. Both have expect function, which does more or less what you explained in video.
@animowany111
@animowany111 7 лет назад
Except that .expect causes a panic (aka program halts) if the result is error, or option is missing. This encourages passing the error state further up in the program, which may or may not be a good thing. (You lose information on what initially caused the error, but functions can handle errors gracefully)
@thalesfm
@thalesfm 7 лет назад
Passing the error along works similar to how exceptions do on other languages, but it generates more predictable control flow than using try-catch blocks IMO.
@rebuffedsalmon6264
@rebuffedsalmon6264 7 лет назад
How can I get the source code for his code editor? I have the executable, but I would really like to port this code editor so that it can be used in newer versions of Windows.
@Bisqwit
@Bisqwit 7 лет назад
It is not very portable code. It is designed around the limitations of 16-bit DOS and the obsolete pre-standard Borland C++ compiler, with only enough testing that it _appears_ to work in videos. If you search the comment sections of enough of my videos, you will eventually find the source code, but I highly suggest you do not waste your time with it, for reasons explained above and below. I would not even have made the editor to begin with, but Joe, the editor that I _actually_ use for all my programming, does not run in DOS, and back when I began making these videos, DOSBox was practically the only environment where I could record videos because all my computers were too slow for desktop recording. So I made a clone of Joe (well, nowhere nearly as full-featured, but with enough features to be able to show editing in a video). You are much better off running the real thing, which is Joe. Aside from the Mario, it looks and behaves exactly the same. It even runs in Windows, if you install either Msys (www.mingw.org/wiki/msys) or Cygwin (www.cygwin.com/). You can see me using it in Windows in this video: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-7IeO7CYFd9E.html
@multimartax
@multimartax 7 лет назад
great video as always, can't wait for the next
@mariosprokopakis4868
@mariosprokopakis4868 7 лет назад
Can anyone explain to me why there is a deadlock in the mutex example when there are is only one thread?
@Bisqwit
@Bisqwit 7 лет назад
Consider this simple¹ implementation of a mutex: struct mymutex { private: volatile bool locked = false; public: void lock() { while(locked != false) { /* busyloop */ } locked = true; } void unlock() { locked = false; } }; Now consider what happens if we have this code: mymutex test; test.lock(); test.lock(); // lock again The first time around, lock() will test “locked” and see it’s false. So it will not loop. It sets “locked”=true. The second time around, lock() will see “locked” is not false, so it will loop, waiting for _someone_ to set it false. And it never happens because it is a single-threaded program, so it loops forever, jamming the program. In my example this situation happens because the lock is acquired at the beginning of WriteBytes(), and while the lock is being held, WriteBytes() calls WriteByte() that also tries to lock the mutex. So, two lock() calls without an unlock() in between. _____________ ¹) This is simple, but actually _unsafe_ for use with threads. Its merit is it’s concise enough to drive the point across without having to explain atomic compare-and-swap functions.
@mariosprokopakis4868
@mariosprokopakis4868 7 лет назад
Bisqwit thank you very much for the explanation, I got it now. In fact I didn't see that WriteBytes calls WriteByte( I don't know why I didn't see that lol) and I thought that it was a trivial race condition problem with multiple threads but I couldn't find the multiple threads in the main. Thank you again for the time you dedicated to answer to my question. Keep up the good work! PS I didn't know about reason parameters and I have to say that your idea is very helpful and I am thinking of trying it out on my projects too.
@Green-zp4le
@Green-zp4le 5 лет назад
First of all, thanks for all the effort you put into your videos -- they're great and enjoyable to watch :-). Have you considered poking a bit into type theory and constructive mathematics? It turns out that there is an isomorphism between writing programs and proving propositions in logic (called the Curry-Howard isomorphism). In essence, it tells us that we can write our propositions as types in a programming language, and any program that inhabits that type is a proof of that proposition. Programming languages such as OCaml make use of this idea to implement something akin to propositional logic, but it is taken to a more of an extreme in proof assistants like Agda and Coq. A middle ground would probably be Haskell, which has a couple of more practical features of such type theories, but doesn't push it to an extreme and aims to be a programming language first. In essence, what this lets us do is express some of the invariants that we want our code to obey and we can check that it's the case statically (modulo implementation bugs, of course!). I'd be quite interested in seeing video from you trying to convey these terms in a simpler way and demonstrating some of the more fun aspects of it :-) (I am more than happy to answer any queries you might have, by the way). Thanks again for all your effort!
@Bisqwit
@Bisqwit 5 лет назад
It is a bit too academic and theoretical for my interests.
@Green-zp4le
@Green-zp4le 5 лет назад
Fair enough, keep up the good work regardless! :-)
@peace2941
@peace2941 6 лет назад
Hello, just discovered the channel and i was wondering what tool he was using to auto type the code, i searched for it on his website but didn't find anything Thanks
@Bisqwit
@Bisqwit 6 лет назад
Maybe you need to watch a video instead: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-5Da6ZyQJjE0.html
@peace2941
@peace2941 6 лет назад
Thank you sir for the quick answer, awesome job !!
@jerrisharun4419
@jerrisharun4419 7 лет назад
I want to become chess player but I started chess career at age of 19 but I'm amateur player ....I seen many biography of chess players like Bobby Fischer Carlson anand they started to play chess ..At age of 6 ..I feel confused ...Im helpless please give me a steady mind....And I wanna become programmer but idon't know what to choose ...Im confused I don't know abt programming but u started to play pc ...And operate at 1st grade ...But I'm having interest I can sit in front of pc 24 hrs a day ...I don't know what to do...pls help me....Sorry for my English I don't know English tat much
@Bisqwit
@Bisqwit 7 лет назад
English is not your problem, but punctuation is. It is the style where you trail off with "…" every few words, as if you are _wind,_ speaking into the wind: Words with no beginning and no end, no structure, just passages and pieces from an endless stream of thoughts. You are a human being. Learn to use punctuation other than "…".
@EnvyThaGamez
@EnvyThaGamez 7 лет назад
Bisqwit, I am very interested in learning python since talking to my Father's cousin who is an astrophysicist. She described how the language is quickly being widely used. For instance, she mentioned how NASA is beginning to adopt python and how the language being "modular" is one of its strengths. However, I still do not know the best method to approach learning it. Could you recommend a strategy, or the best resource for learning in your opinion? I love everything you have done on this channel!
@Bisqwit
@Bisqwit 7 лет назад
Python is a language I usually recommend for beginners, too. But to be honest I have no idea where you would go for material for beginners to learn Python programming. Not because it does not exist, but because I have not been looking for such material. I am pinning your post to give it more visibility for a moment so that others can hopefully give good answers!
@jchevertonwynne
@jchevertonwynne 7 лет назад
reddit r/learnpython had a load of resources on the sidebar, you might find them useful i really love python, favourite language i've used yet. so much quicker to write than java, and you basically write pseudocode that works!
@EnvyThaGamez
@EnvyThaGamez 7 лет назад
Thank you!
@jimmoriarty3381
@jimmoriarty3381 7 лет назад
if you're willing to pay some money, you can check out the programming courses on udemy.com. At the time of writing this they're charging just 19.99 i got it and it seemed pretty gooooood(idubbbz). Also check out this website : www.stavros.io/tutorials/python/. It goes through the basics of python very swiftly. not saying u'll learn python in the 10 minutes it suggested, but it will definitely be a worthy read for someone interested in python(WARNING: it will be MUCH easier to read if you are already familiar with programming, but still, u know, just save the page and maybe it'll help you one day :)
@Anlerolo
@Anlerolo 7 лет назад
Hi Bisqwit, many people use Python in combination with C++. It helps getting more out of your time, as you obtain the advantages of both languages. Perhaps it could be a good theme for a tutorial video. Thanks for your videos, they are great!
@kamilchen4
@kamilchen4 7 лет назад
thank you!
@haroldmcbroom7807
@haroldmcbroom7807 5 лет назад
We think along similar lines, but you address a part of an equation I thought would never be possible... The _"Why"_ In robotics, we'll never have anything less than a chat bot, unless we teach the machine to respond based on it's purpose and proximity to others around itself, and attempt to solve the who, what, when, and where of the person it has come into contact with. Using this algorithm, I hypothetically take it a step further. A virus... The mind is to the human what a virus is to a machine; Who says a virus has to be bad, it's only the purpose for which you use a virus that determines moral intent. I propose the following, if it is at all possible... Game Concept to solve the problem of semi-spontaneous Artificial Intelligence within NPC's in a video game, to relieve the pressure of the master program having to do all the work itself. Artificial Intelligence, in my opinion should be external to the master program, rather than the program controlling dozens of AI's at any given time. Introduction to a limited virus that is quarantined within the confines of the gaming environment, it's only purpose is towards self-awareness, survival, and being aware of it's surroundings. Example Player Harold leases some space aboard a Space Station, and decides to turn that space into a Fast Food burger joint. He furnishes the restaurant, buys a cash register, and a computer for Human Resources related tasks, the only thing missing is the employees. He accesses his computer and goes to the Job Board, clicks on the food industry, and looks at all the possible NPC candidates and the skills they will bring to the job. These NPC's are not yet in the game, but once Harold clicks "hire", the game creates these NPC's and a virus is attached, giving it "life". Each spawned NPC has a "checklist" assigned to it, sort of like a pre-flight checklist in the aviation field. But this "checklist" is for AI's. It starts asking questions... How is my health... Am I hungry, thirsty... What do I want to do... My checklist says I have a job lined up, so I better be on my way, as I do not want to be late on my first day on the job. Per our agreed upon contract, I will be working such and such hours, but after that I am free to do as I please... but while I'm working, my mind must stay focused on the job. With every AI in the game, asking and answering the questions on their personalized check list, we create a game in which the AI's feel spontaneously real. Some jobs AI's take, after the required positions have been filled, may act as stepping stones to bigger and better paying job opportunities, after they've met the prerequisites having worked a lower end job, meaning, some of them have aspirations to rise above their current jobs, to pursue other opportunities, but recognize in order to meet a long term objective, shorter term goals must first be met. My question to you, Mr. Bisqwit, is such a virus possible, and how small can a virus be, if it's only task is to access data from some form of checklist, whatever efficient manner we can come up with to achieve this, as well to figure out path finding in order to reach those locations. There's also the concept of "virtual variables", which are variables in game, that are only visible in scope to AI's based on their training. For instance if an AI is trained in engineering, will not have access or even be aware of medical related events on screen, thus, AI's only have access locally to those events they are qualified for, and that goes for the player as well.
@ricardo.mazeto
@ricardo.mazeto 7 лет назад
termbin.com/4d6b. What does this code do? Is this supposed to be an easter egg or its just a random IOCCC entry? I pipe random strings into it, it just cuts the 1st 5 letters.
@Bisqwit
@Bisqwit 7 лет назад
Here is the proper way to invoke that program: cat title-key scrambled.vob | ./efdtt >clear.vob You can find the source code in its originally released form here: www.cs.cmu.edu/~dst/DeCSS/Gallery/bowley-efdtt-dvdlogo.html
@ricardo.mazeto
@ricardo.mazeto 7 лет назад
Hmm, turns out that this code unscrambles CSS, the DVD standard's copyright protection mechanism, from a .vob file. Cool! Thanks Bisqwit.
@wbuchmueller
@wbuchmueller 7 лет назад
Another name for this approach could be "Reason Driven Development" or RDD for short since we already have TDD etc.
@MrVankog
@MrVankog 7 лет назад
Wilhelm Buchmüller at the start of the video I was compelled to call it the same as Behavior Driven Development. But his examples showed me that justified programming is on a much lower level.
@Bisqwit
@Bisqwit 7 лет назад
I appreciate the synergy, but unlike Test Driven Development, what I introduce in this video is not a mechanism that _drives_ the entire development process. It is just a way of annotating your code in a way that may provide benefit in future at both run time and when reading source code. Unlike TDD, it can be even added as an afterthought.
@lehuynh7637
@lehuynh7637 3 года назад
3:41 which program that you used to separate windows?
@Bisqwit
@Bisqwit 3 года назад
Libreoffice Impress.
@niteshmalani3742
@niteshmalani3742 5 лет назад
I have .Ex4 file can you teach me how to remove protection on it. Is it possible ?
@Bisqwit
@Bisqwit 5 лет назад
Never heard.
@niteshmalani3742
@niteshmalani3742 5 лет назад
@@Bisqwit give me your email I will sent you .ex4 file kindly check and tell me in this file eiditng is possible ?
@niteshmalani3742
@niteshmalani3742 5 лет назад
@@Bisqwit how to convert Ex4 file in source code ?
@wojciechsura
@wojciechsura 2 года назад
"Every fool can write code, which is understandable by the computer. Good programers writes code, which is understandable by humans"
@IrizarryBrandon
@IrizarryBrandon 7 лет назад
This looks like a pretty good idea, actually. :)
@christopherchamberlain8477
@christopherchamberlain8477 6 лет назад
The only problem I have with this style of coding is the runtime cost of doing this. It'd be hard to justify a reason parameter if its used in a situation that is already occupying heavy memory or tight loops that execute 10 million times... but if there was a way to develop this pattern into a compile time removal ( like #DEFINE #IFDEF stuff ), then this might be a interesting pattern to follow.
@Bisqwit
@Bisqwit 6 лет назад
Obviously no guideline is to be applied religiously in every possible situation.
@christopherchamberlain8477
@christopherchamberlain8477 6 лет назад
Woah, thanks for the instantaneous reply O_O . Anyway, this seems quite useful, and I'm sure I've implicitly done this sort of thing to fix problems in the past without thinking about it as a specific sort of pattern. I can imagine myself, inserting this into the code... solving the bug, and then removing it.
@skejeton
@skejeton 2 года назад
As an option, a global could work, or some kinda registry
@akj7
@akj7 6 лет назад
Clap Clap Clap. This is really impressive. I do want to know why you work as a bus driver while you seem to have more programming knowledge than most programmer i know and maybe the story about your family.
@kari4056
@kari4056 6 лет назад
I miss you bis;(
@chaorrottai
@chaorrottai 5 лет назад
Why not use lock guards? Or a variable wrapper with a lock and lock guards? I just recently wrote one myself, tested it against many threads as win10 will let me generate. // Thread safe primitive/object wrapper template class tsafe { public: template tsafe(z val){ var = val; } t get() { std::lock_guard destrMutex(mut); return var; } bool set(t& val) { std::lock_guard destrMutex(mut); return var = val; } void directAccess(std::function func) { std::lock_guard destrMutex(mut); func(var); } // BASIC OPERATOR OVERLOADS // Asingment bool operator =(tsafe val) { std::lock_guard destrMutex(mut); var = val.get(); return true; } template bool operator =(z val) { std::lock_guard destrMutex(mut); return var = val; } // Addition t operator +(tsafe val) { std::lock_guard destrMutex(mut); var += val.get(); return var; } template t operator +(z val) { std::lock_guard destrMutex(mut); var += val; return var; } void operator +=(tsafe val) { std::lock_guard destrMutex(mut); var += val.get(); } template void operator +=(z val) { std::lock_guard destrMutex(mut); var += val; } // Subtraction t operator -(tsafe& val) { std::lock_guard destrMutex(mut); var -= val.get(); return var; } template t operator -(z& val) { std::lock_guard destrMutex(mut); var -= val; return var; } void operator -=(tsafe val) { std::lock_guard destrMutex(mut); var -= val.get(); } template void operator -=(z val) { std::lock_guard destrMutex(mut); var -= val; } // Division t operator /(tsafe& val) { std::lock_guard destrMutex(mut); var /= val.get(); return var; } template t operator /(z& val) { std::lock_guard destrMutex(mut); var /= val; return var; } void operator /=(tsafe val) { std::lock_guard destrMutex(mut); var /= val.get(); } template void operator /=(z val) { std::lock_guard destrMutex(mut); var /= val; } // Multiplication t operator *(tsafe& val) { std::lock_guard destrMutex(mut); var *= val.get(); return var; } template t operator *(z& val) { std::lock_guard destrMutex(mut); var *= val; return var; } void operator *=(tsafe val) { std::lock_guard destrMutex(mut); var *= val.get(); } template void operator *=(z val) { std::lock_guard destrMutex(mut); var *= val; } // COMPARISON OPPERATORS bool operator = val.get(); } template bool operator >=(z& val) { std::lock_guard destrMutex(mut); return var >= val; } bool operator ==(tsafe& val) { std::lock_guard destrMutex(mut); return var == val.get(); } template bool operator ==(z& val) { std::lock_guard destrMutex(mut); return var == val; } bool operator !=(tsafe& val) { std::lock_guard destrMutex(mut); return var != val.get(); } template bool operator !=(z& val) { std::lock_guard destrMutex(mut); return var != val; } private: t var; std::mutex mut; };
@Bisqwit
@Bisqwit 5 лет назад
This implies you have the full C++ standard library at disposal. I was just doing an example, and to make the code actually compilable by most people (so that it is not entirely just hand-waving) I used std::mutex. Ignore that, just imagine it is some platform-specific thing like core_util_atomic_cas_u8() from mbed. The point is not threads. The point is provide a trace of rationales. By the way, why did you write one yourself? Standard C++ has prefectly good std::unique_lock and std::lock_guard already.
@ElSanto0044
@ElSanto0044 7 лет назад
Cool to the core
@Rand0081
@Rand0081 5 лет назад
"We spend effort in naming functions, variables, methods and function parameters meaningfully [...] just so we can understand later." You don't know how much you are way too much optimist.
@metaorior
@metaorior 3 года назад
i love you man.. you are of my family
@grproteus
@grproteus 4 года назад
This should be taught at Programming 101.
@ZLau13
@ZLau13 7 лет назад
Hey are you a professional developer these days? I thought you drove buses! Tell me about it, I'm curious :)
@inimk
@inimk 7 лет назад
luutifa0 >> I heard that he wanted to get away from programming so be became a cab driver. I hope he got over it :)
@Bisqwit
@Bisqwit 7 лет назад
The bus company downsized due to competitive tendering, and I lost my job 1,5 years ago. Nowadays I do embedded programming at Etteplan IoT (former Espotel).
@xamael1989
@xamael1989 7 лет назад
You sir are great programmer
@phildem414
@phildem414 2 года назад
Something to think about ! 🤔 Principles always rule.
@Embedonix
@Embedonix 6 лет назад
Well, very good reasons...but in embedded systems....that would cause too much overhead :(
@Bisqwit
@Bisqwit 6 лет назад
It really depends. The mutex example I showed in this video is (modified) from an actual project at work. It runs in a 8 MHz processor with 20 kilobytes of RAM, and it is not too heavy.
@redsusoverparadise2700
@redsusoverparadise2700 3 года назад
This has what had happened after I let my computer scan a philosophy book.
@MateoHrastnik
@MateoHrastnik 7 лет назад
In my opinion adding a why-parameter feels kind of hacky. If C++ had some kind of way to implement reflection this could be done without burdening the user of the function with the need to pass parameters that are unneeded for the function to actually work. However, as C++ has it's limitations, I guess the why-parameters are a better-than-nothing method for preventing bugs or speeding up bug-fixing.
@perplexedmoth
@perplexedmoth 7 лет назад
H& 1Cloud it's in the video where he passes a const char *why parameter for runtime diagnostics purposes to critical functions.
@Bisqwit
@Bisqwit 7 лет назад
1Cloud, that question is answered in the video. Suggest you watch it before replying to comments concerning its content. :-)
@Bisqwit
@Bisqwit 7 лет назад
There are captions too. And even on-screen interstitial headers/plaques that say as much. I mean, why are you here if you are not watching/listening the video?
@MrGeekGamer
@MrGeekGamer 7 лет назад
I don't really think that adding a lot of extra code to explain why is any more helpful than say, adding assertions in most cases.
@wallabra
@wallabra 4 года назад
pair? What?! Also, you're aware std::string is an owned type and you just copy it over the whole prot array, right? Just use a std::string* pointer type (or std::shared_ptr), and set those values to its address. (If scope becomes an issue, push it to a reference-counted reason set, and point at the item there instead!) And, instead of the redundant bool value, just initialize it to NULL :) Either way, I do like the concept! I do not like that it mostly depends on runtime execution aspects, like the stack and function arguments. I would prefer if it were more transparent, so that while it does not affect execution, things like debuggers could easily fetch attached justifications to function calls or expression fragments (akin to how Python attaches docstrings to callables!).
@Bisqwit
@Bisqwit 4 года назад
Yes, I am aware that the string is getting copied. For a 512 kiloelement array with 20-character labels this means like 10 MB of RAM used. It is a cheap price to pay of simplicity of programming. The moment you introduce pointers, the program complexity increases: Null pointer dereferences, use after free, circular dependencies, memory leaks, all that stuff. Stuff that may come bite you causing perplexing crash/corruption issues the moment you are not paying attention. You are adding hurdles for the programmer for no reason. It is better to have code that you can identify on sight that this _works_ and can cause no issues. The more tightropes you add, the more likely someone will fall and injury themselves. A ROM hack insertor program is not a performance critical piece of software. _If_ this developer tool occupies 200 MB of RAM for the whole 20 seconds that it runs while linking stuff, compressing images and so on, and you run it on a laptop that has 2 GB of RAM, it is hardly worth spending optimization effort in.
@wallabra
@wallabra 4 года назад
@@Bisqwit Well, all that stuff that bites you will only bite you wherever you use it, which is why you need to keep the code modular. In this case, you should perhaps add a few extra functions (and make them static or protected or something) that handles the low-level details of storing strings as pointers for you, while returning an empty string if the pointer is NULL. May I take a better look at it? I'd love to help! Perhaps as a fork, but nonetheless!
@didaloca
@didaloca 6 лет назад
Took me far too long to realize why lock was being called twice.
@LambOfDemyelination
@LambOfDemyelination 6 лет назад
Will you ever do a video on any of the popular interpreted programming language such as Ruby, JS or Python?
@Bisqwit
@Bisqwit 6 лет назад
Maybe! I don’t know. I mostly make videos about topics that excite me at some particular time. I haven’t been doing anything with Ruby, JS or Python in a long time.
@hexwrench4433
@hexwrench4433 7 лет назад
Just make sure your sober or you'll be caught in an ever increasing anger loop.
@radityaarhya
@radityaarhya 6 лет назад
Where are you bisqwit ?
@Bisqwit
@Bisqwit 6 лет назад
Hello! I am still making videos. The current ones just happen to be taking long time to make. You can follow me on Twitter, I post updates there regularly about my videos and random things I have on my mind. twitter.com/RealBisqwit You can think of it as the official blog of my RU-vid channel, as long as RU-vid itself does not have this sort of tool.
@srjskam
@srjskam 7 лет назад
Drive Ř. What's the story behind that?
@Bisqwit
@Bisqwit 7 лет назад
That letter occurs in the Czech language. In my early childhood I watched some children’s tv shows that were made in Czechoslovakia, and while they were dubbed in Finnish (and thus I was denied the opportunity to learn anything about the language or about its phonology), the letter Ř sat in my head until many years later when I figured out why it’s in my head. I decided to honor this fact in this video when I was making a faux command prompt.
@srjskam
@srjskam 7 лет назад
A fine letter, probably best known from Dvořák. Sometimes accented letters are a bit opaque, but ř does look like it sounds, something like ž+r.
@Bisqwit
@Bisqwit 7 лет назад
You have a penchant for languages, I gather.
@srjskam
@srjskam 7 лет назад
You could say that. Unfortunately my knowledge of languages is wide but very shallow.
@kopuz.co.uk.
@kopuz.co.uk. 6 лет назад
yes do this so i can easily debug your work without symbols :0~
@Kart4Lake
@Kart4Lake 5 лет назад
i realize that autogen english subtile with NO mistake!
@Nellak2011
@Nellak2011 5 лет назад
Anyone else expecting to see an esoteric programming language?
@sqoonman
@sqoonman 5 лет назад
Sad, because i could give only one like :(. Thank you so much for this tip
@CTimmerman
@CTimmerman 6 лет назад
My docstrings justify my commands.
@niteshmalani3742
@niteshmalani3742 5 лет назад
How to convert source code ?
@Bisqwit
@Bisqwit 5 лет назад
Into what?
@niteshmalani3742
@niteshmalani3742 5 лет назад
@@Bisqwit I have .Ex4 extension file and I don't know how to convert this file or how to editing this file ..can you check this file and tell me ..sent me your email so I sent file into your email
@Bisqwit
@Bisqwit 5 лет назад
You spoke of source code. From: en.wikipedia.org/wiki/Source_code Quote: *In computing, source code is any collection of code, possibly with comments, written using a **_human-readable_** programming language, usually as plain text.* As for your Ex4 file, look into the documentation of the program that you made the file with.
@niteshmalani3742
@niteshmalani3742 5 лет назад
@@Bisqwit this is only for how to coding source code ...I don't need this How to edit .ex4 file ?? How to decompile .ex4 file ??
@Bisqwit
@Bisqwit 5 лет назад
Look into the documentation of the program that you made the file with.
@TeboShepherd
@TeboShepherd 2 года назад
Oh man I wonder what the original 'a bit too pretentious' name was? Was it G0dØfK0D3? Or TheBestFinn?
@Bisqwit
@Bisqwit 2 года назад
Something like that.
@tomascanevaro4292
@tomascanevaro4292 7 лет назад
What did you study in collage?
@Bisqwit
@Bisqwit 7 лет назад
“College” is a USA/Britain thing so the answer is _mu._ I went to a trade school (en.wikipedia.org/wiki/Vocational_school) in the 1990s, but the line was electrical engineering; there was no computer programming related school (that I knew of) back then. After that and after army, I went to this kind of school: en.wikipedia.org/wiki/University_of_applied_sciences_%28Finland%29 , but I never finished even a year (and all I learned there was some physics and math, which the education system seemed overwhelmingly biased towards) because I got full time employed.
@TheSuperTubeMan
@TheSuperTubeMan 7 лет назад
I assume then you are self-taught?
@chrisd4157
@chrisd4157 7 лет назад
> and all I learned there was some physics and math Isn't that useful for Embedded development? As far as I know, Signal Processing, Control Engineering, Hybrid Systems and so on are big parts of it and they're based on Math and Electrical Engineering. But I don't know anything about Embedded jobs in practice. I'm still a CS student. Is a good grasp of Electrical Engineering helpful in your job? I'm looking at Embedded as a possible field I'd like to go into after Uni (I like low-level development) but my EE (and Physics) skills are almost non-existent currently. I'm planning to fix that eventually though.
@prilik
@prilik 7 лет назад
If anyone wants to take a crack at deciphering the code that borders the video, here is a pastebin of it :) QHJR3kzi
@Bisqwit
@Bisqwit 7 лет назад
You can post full URL links too. Also check out the prior comments. Also, your pastebin gives “This page is no longer available. It has either expired, been removed by its creator, or removed by one of the Pastebin staff.”
@prilik
@prilik 7 лет назад
Whoops, didn't see that 😅 Neat!
@pardal_bs
@pardal_bs 4 года назад
I really thought this was a joke at first.
Далее
Выпускаем трек? #iribaby
00:14
Просмотров 431 тыс.
What are EXE files made of?
11:00
Просмотров 144 тыс.
What is the Smallest Possible .EXE?
17:57
Просмотров 305 тыс.
Linus Torvalds Guided Tour of His Home Office
4:25
Просмотров 1,6 млн
Comparing C to machine language
10:02
Просмотров 5 млн
C++ vs Rust: which is faster?
21:15
Просмотров 383 тыс.