The Beauty Of Doom 3 Source Code

  Рет қаралды 535,272

ThePrimeTime

ThePrimeTime

6 ай бұрын

Recorded live on twitch, GET IN
/ theprimeagen
Reviewed article: kotaku.com/the-exceptional-be...
By: Shawn McGrath
MY MAIN YT CHANNEL: Has well edited engineering videos
/ theprimeagen
Discord
/ discord
Have something for me to read or react to?: / theprimeagenreact
Kinesis Advantage 360: bit.ly/Prime-Kinesis
Hey I am sponsored by Turso, an edge database. I think they are pretty neet. Give them a try for free and if you want you can get a decent amount off (the free tier is the best (better than planetscale or any other))
turso.tech/deeznuts

Пікірлер: 628
@lordfrz9339
@lordfrz9339 3 ай бұрын
People who dont like comments havent had to deal with 30yr old code that was done by a guy whos been dead for 12years.
@alexale5488
@alexale5488 18 күн бұрын
I don't know man, but programmers tend to be some of the most arrogant and annoying people I've worked with. They attach to some crap and stick with it till the end, bullying others for not doing things their way. I always add comments where my code isn't really self-explanatory.
@lordfrz9339
@lordfrz9339 18 күн бұрын
@@alexale5488 I know the type of people, super annoying lol.
@ZM-dm3jg
@ZM-dm3jg 18 күн бұрын
well we have AI tools now that are brilliant for commenting / explaining 30 year old legacy code. So this is a problem for past generations and won't be a problem again for us until we all lose our jobs to AI anyway
@jal051
@jal051 16 күн бұрын
@@lordfrz9339 Some guys reaaaaaally love pissing contests. I think we all know a couple of these, lol
@Grumpicles
@Grumpicles 15 күн бұрын
​@@ZM-dm3jg except AI can't tell you the intent and "why" of the code, which outside of code complexity is a large part of code commenting.
@ExpensivePizza
@ExpensivePizza 6 ай бұрын
"Sometimes, the elegant implementation is just a function. Not a method. Not a class. Not a framework. Just a function." -- John Carmack
@GaryChike
@GaryChike 6 ай бұрын
Reminds me of trying to implement a simple 'enum' in Kotlin but find out it only has an 'enum class' - ugh
@nyzss
@nyzss 6 ай бұрын
literally C, its the hardest, yet most simple language. You only mostly deal with functions, nothing else.
@Yupppi
@Yupppi 6 ай бұрын
"I'm trying to make Quake in Haskell btw, for fun btw, on ipad on the go btw" -John Carmack
@Wobbothe3rd
@Wobbothe3rd 6 ай бұрын
Carmack wrote a detailed post on Functional programming, its on facebook still.
@MrSlowestD16
@MrSlowestD16 6 ай бұрын
That's not a concept the OO die-hards can wrap their head around. People are taught in school that OO is *always* preferable, and some carry that for life. It often is a good pattern, but always using it is just silly (IMO).
@martijn3151
@martijn3151 6 ай бұрын
Just wait until you need to port a Japanese game from the 90s to present day consoles… you will absolutely love comments.
@dragonmyballs
@dragonmyballs 6 ай бұрын
Sure… I can wait
@JonLundy0
@JonLundy0 6 ай бұрын
What good would Japanese comments do for me?
@chalkp
@chalkp 6 ай бұрын
Until you encounter C# variable names in japanese
@khatdubell
@khatdubell 6 ай бұрын
@@JonLundy0 Probably make you laugh. kzbin.info/www/bejne/mJfFk4Zpgbl2kLs
@NeoShameMan
@NeoShameMan 6 ай бұрын
Chat gpt: exist
@Tibbon
@Tibbon 6 ай бұрын
I had hoped this video to be an original look through of the Doom 3 source code it is a 40 minute ramble about someone's blog post.
@lukekurlandski7653
@lukekurlandski7653 6 ай бұрын
@16:00 I think a little vertical whitespace can be considered a form of self-documenting code, as it can help group statements in a function together based on their purpose and demarcate these ideas from others.
@ttthttpd
@ttthttpd 6 ай бұрын
Basically the "headline technique", with the leading comment removed if it's too obvious what the chunk of code has in common.
@AdroSlice
@AdroSlice 6 ай бұрын
It's very important though to not stick to some rigid guidelines here, but rather think about what makes sense. Got a string you're adding to over the course of the loop? Put it right before your loop with no extra spacing. Final returns usually like a bit of space too.
@apollolux
@apollolux 6 ай бұрын
Vertical whitespace is for when Tom doesn't implement comment parsing in JDSL. ;)
@TheNewton
@TheNewton 6 ай бұрын
pffft imagine using whitespace like instead for writing ancient Aramaic or Scriptio Continua.
@keldencowan
@keldencowan 6 ай бұрын
For context, the Wayback Machine shows the missing code example images as preferring K&R style brace placement over Allman style. I.e. curly braces on the same line as if/else rather than their own line. Edit: if only I had waited until 21:30 before commenting
@MrSlowestD16
@MrSlowestD16 6 ай бұрын
Having worked in SW for many years, for me what defines a beautiful code base is very simple: When somebody gives you an initial ticket to add some functionality, as usually happens when you 1st join a team, without knowing the code base, it should be super simple to track down where code needs to be added, look at the surrounding code, and figure out how to augment it to do what you need. If that can all be done in a short time frame, than IMO the code is beautiful. And that's all there is to it, IMO. Code needs to be maintained & built upon, it's as simple as that. So as long as it's easily approachable and readable? It's good.
@TBTapion
@TBTapion 6 ай бұрын
"Code should be self-documenting" is a very funny point. I had an interview once at a consultancy where one part of their technical interview was some kind of code analysis. They gave me a short piece of code where they said to assume it runs fine and has no errors. The task was to somehow make it better. They left the room and gave me some time to think. My simple answer when they got back was "more self-explanatory function and variable names", which they sort of accepted, I think, but they mainly wanted comments in there. Worst technical interview I've ever had. I kinda failed that one, and had another one at the same company where we spent an hour talking about a developer roadmap. (Should probably say the code wasn't that complex, getting an item from an array and some other functions) Had two other technical interviews at two other places that were both sort of a pair programming session to write some unit and integration tests. Those were much better
@andywest5773
@andywest5773 2 ай бұрын
Be very glad you didn't get the job. Somebody once said, "A comment is a failure to express yourself in code. If you fail, then write a comment; but try not to fail."
@swozzlesticks3068
@swozzlesticks3068 Ай бұрын
​@@andywest5773 I very much don't like this idea. I come from a numerical analysis background (focus on computation to approximate mathematical problems) and what I've learned from the math side of things is that you should not assume that people can pick up on your ideas instantly. It is extremely common in mathematical proofs to write a sentence after 1 line just to explain the connection. I can read all of my proofs without any annotations (comments) because my brain has gone through the motions already. However, if I were to present that proof to a colleague without any annotations whatsoever I would most likely need to elaborate on steps for them to understand it *quickly*. I fully believe a piece of software can be the same way. I've been presented with long R programs without any comments and just gone "dude what the fuck is going on here". But after like 5 minutes of discussion with the author, I had perfect clarity. And this back and forth could certainly have been avoided with comments. You may say "if you could understand code better, or your coworker could code better (or vice versa), then this issue wouldn't exist in the first place." To that I would say maybe, but I'd also say that it's an unrealistic expectation to expect excellence out of coworkers/colleagues. I think it's a much better mindset to expect excellence out of yourself while still providing guidance in the form of comments for others.
@elzabethtatcher9570
@elzabethtatcher9570 6 ай бұрын
I am not a rust dev, nor am I using htmx, but I totally felt soulbros with Prime when he pulled out his "Devtools" and started removing annoying html blocks from the page he reads. I do that with ublock. I also separate code blocks with empty lines, it is like commas to me: you can read without them, but it is nicer.
@jasondoe2596
@jasondoe2596 6 ай бұрын
Commas are a great analogy.
@TheAscense
@TheAscense 6 ай бұрын
I think of it like paragraphs in text, I like to space out blocks that feel like they share a common "idea". The spacing is a bit arbitrary, and there is usually not an obvious right answer as to what is grouped together and what is spaced apart, but simply having it makes the code flow better, and not having it makes code feel way more tiring to read.
@daedalus5070
@daedalus5070 6 ай бұрын
I laughed hard when he asked if it was floating. Backend developers still think its the early 2000's
@mystrdat
@mystrdat 6 ай бұрын
Nobody uses htmx bro
@spankyjeffro5320
@spankyjeffro5320 5 ай бұрын
Nope. Commas and other forms of proper punctuation are always mandatory. No exceptions.
@CallousCoder
@CallousCoder 6 ай бұрын
That “unlock a problem solving way” is the fondest memory of my dad an I when he showed me away to solve this Hanoi Towers puzzle in 4 or 5 lines of code. Teaching me 15 year old me about recursion. And after he showed that magic told me to avoid using recursion whenever you can or are 100% sure it can’t cause a stack overflow.
@manawa3832
@manawa3832 3 ай бұрын
telecommunications is the hardest "medium" to program in. actually it's typically regarded as the most difficult, highest failure rate and highest expert level (meaning need longer time to establish seniority) than any other field.. in human history. i kid you not those people are doing the hardest engineering in the world only for a rogue cosmic ray to flip a bit in their L5 switch and yet somehow companies like cisco are able to maintain 99% uptime for everyone. it is a massive feat that no one notices.
@robwalker4653
@robwalker4653 5 ай бұрын
The reason a lot of people don't like having curly braces on the same line is so you easily tell which curly brace relates to which other curly brace quicker. In a lot of IDE's you highlight one and it highlights the other. When are in the same horizontal position it jumps out much quicker.
@phitc4242
@phitc4242 4 ай бұрын
just press % (in vim)
@jal051
@jal051 16 күн бұрын
I kind of mix it. If it's a very small thing I keep the curly bracket in the same line, but if it's a more considerable block I like to add it in a new line so the block is easier to see.
@AustinSnider
@AustinSnider 5 ай бұрын
If you checkout Carmack's contribution to the Meta Quest codebase re: VR motion controller, you'll see lots of highly detailed ASCII art schematics showing the system and then a bunch of beautifully self-documented stuff.
@Isotech
@Isotech 6 ай бұрын
I love this commentary for four reasons: 1. Operator overloading. I hate it someone made a a bit shift into a string concatenation.. 2. I spent to many hours debugging ATL/STL in the late 90s/early 2000s. That was incredibly frustrating. 3. API design. Focus on clarity, not cleverness. I appreciate you highlighted that. 4. I have my copy of effective c++ right behind me. Thanks for that reference.
@jal051
@jal051 6 ай бұрын
16:00 I definitely prefer spacing in blocks. I find it infinitely easier to read (even when I wrote it myself) when there are separations. And as far as I remember doom3 source does it. I only surfed it a couple of times, but I've worked a lot with Quake 2 and Quake 3 source code and they definitely leave space in those. Also, it should be noted that Doom3 was iD's first project using C++. They used C for all their previous projects, so Doom3 is C++ with a heavy influence of their C habits. (I suspect they only moved to C++ because the people who used to license the engine were requesting it to be C++)
@MrHaggyy
@MrHaggyy 6 ай бұрын
John Carmack still writes mostly C code. He only uses C++ abstractions if the repetitive pattern appears those should solve. He told this in many interviews, most prone Lex Fridmans.
@Wobbothe3rd
@Wobbothe3rd 6 ай бұрын
@@MrHaggyy there's actually a id software coding style guide that essentially says this. It's linked in the article reviewed here.
@iLLuzion1st
@iLLuzion1st 17 күн бұрын
Check out the open source project: Open Tournament
@WillEhrendreich
@WillEhrendreich 6 ай бұрын
16:30 I like having each function be a discreet paragraph so in vim I can just 'dap' to cut the whole thing or 'vap' to select the whole thing, and then if I'm working in a repl I hit my send to repl button.. Makes it nice.
@khatdubell
@khatdubell 6 ай бұрын
In regards to writing overly generic code and it being ugly. People need to learn they aren't trying to implement standard library functions, that have to be used by millions of people without knowing their exact use case. Use a specific implementation if you don't need something generic. For instance, from the code he provided, he's defining an allocator type, ala the standard library. Most people will _never_ need to pass a specialized allocator to a class, so why would you write a class for your program that allows you to override the allocator? If you find you need that specific class, but slightly more generic, consider making it templated, but again *this doesn't mean you have to go balls to the wall generic* Just support _your_ use-cases unless you're writing a library intended to be consumed by a large array of people with a large array of uses.
@tommclean9208
@tommclean9208 6 ай бұрын
stupid people just love complicated code
@SkywalkerWroc
@SkywalkerWroc 6 ай бұрын
"If your code definition takes more space than body, you probably left the path of good programming" TypeScript: 👀👀👀
@triplebog
@triplebog 6 ай бұрын
I used to work at a game dev company that wrote in C++ and their codebase was not beautiful let me tell you. There was 3 different sets of string handling paradigms that had to be used in different places in the code, Thats right, they had stringhash, stringview, and stringviewhash in 2 or 3 different forms each. It was insane because they weren't even all mutually compatible with eachother.
@Tabu11211
@Tabu11211 6 ай бұрын
logical code blocks gang. Love to bunch things together that are related and then leave a space before the next thing.
@radspiderjackson
@radspiderjackson 6 ай бұрын
honestly watching Prime's content in general, but especially this video is making me realize that UnrealEngines 'version' of c++ isn't any different than regular old c++, they've just sort of handled a lot of what can be considered good c++ practices like the ones mentioned in this.
@RigelOrionBeta
@RigelOrionBeta 6 ай бұрын
Pretty much. And the garbage collector. But certain parts of the engine aren't garbage collected, so you use smart pointers instead.
@phitc4242
@phitc4242 4 ай бұрын
@@RigelOrionBeta bruh what XD average c++ moment I guess (I only program in C please don't hurt me)
@migo70
@migo70 6 ай бұрын
16:00 I personally like it in chunks not one chunk. I can't read the code well if its just one blob of text/characters, if I need to scroll, I'll scroll, it personally amazes me people make it look like its a chore. But each to their own, ultimately it's about who is maintaining the code base, and does it work for everyone who is.
@gJonii
@gJonii 6 ай бұрын
Re: beauty is a function of understanding, to me a defining quality of beautiful code is that as your understanding increases, it makes you like the code more. Bad code, you look at thing, and you might look "that's fine", but later you realize "wait wait WHAT?!" as you understand the horrors going on. Or, you might keep being "meh". But beautiful code, you learn more, you like it more.
@ryanleemartin7758
@ryanleemartin7758 6 ай бұрын
"hair is slowly turning blue from the roots". gottem! Good shit.
@timedebtor
@timedebtor 6 ай бұрын
On input and output, I miss Ada's solution for this. You can declare a function parameter as `IN` `OUT` or `IN OUT`
@CottidaeSEA
@CottidaeSEA 6 ай бұрын
Regarding "one function should do exactly one thing" I think that it is more important to avoid doing things like mutating and persisting in one function than it is to limit to one thing, because "one thing" is highly subjective.
@MenkoDany
@MenkoDany 6 ай бұрын
A function has to do "one thing". The same way a hammer should only be used for hammering. If you think about it for a second, you realise the whole statement is pretty much a nothingburger. Yes, you shouldn't make a function set_player_health_to_100_and_contact_thinkpad_servers_and_download_ThinkPad_T40p_documentation()
@Glazer209
@Glazer209 6 ай бұрын
Put it up there with unit test, which should only test a single unit. But seeing as how the whole phrase is “unitless”, a single unit of what? A single line, a single function, a single class, a single module? Another one of those statements that’s a useful rule of thumb and contains subtlety, but shouldn’t be read literally (see also: DRY)
@CottidaeSEA
@CottidaeSEA 6 ай бұрын
@@MenkoDany Yep! The intent behind the function should appear in the name and the name should be reasonably concise. If you're reaching 10 words in a single function to describe the intent then you probably have a problem. Either the function isn't in the correct place and needs a separate class (or equivalent) or you simply do too much in a single function.
@MenkoDany
@MenkoDany 6 ай бұрын
@@CottidaeSEA the_game("you_lost");
@CottidaeSEA
@CottidaeSEA 6 ай бұрын
@@MenkoDany I see we are people of the same Internet generation and I did indeed lose the game.
@bitwisedevs469
@bitwisedevs469 5 ай бұрын
The no brackets for single statement inside for loop or if can also cause bug if you interpret its scope incorrectly, since then I decided to always add brackets.
@shawn576
@shawn576 6 ай бұрын
I can understand school requiring comments on every line. If I'm a teacher trying to grade your work, do I really want to sit there and figure out what your shit code is trying to do? Write in English what you are trying to do then I can see if the code you wrote actually does what you think it does. Maybe your code does something really cool that I've never seen before, and it would be a shame to mark is as wrong or bad simply because I didn't understand what you were doing. It's important that a student understands what the code is actually doing. If your comment says it does X but the code is actually doing Y, it means you are writing code without understanding it, and that's a problem that needs to be fixed before the lack of understanding breaks something.
@Calypso694
@Calypso694 4 ай бұрын
as someone who is still learning the ins and outs of C and other code stuff i think Commenting is great. Helps me personally have my stars above moment when i had no idea what i was writing when i was writing it.
@Parker8752
@Parker8752 6 ай бұрын
Honestly, the whole thing with getters and setters alongside some methods not requiring a verb because they're literally just returning a value (like with Vector::length vs Vector::getLength) is why I much prefer C# over Java - properties. You get all the benefits of setters and getters with regular value syntax.
@futurexjam2
@futurexjam2 6 ай бұрын
also type erasure in Java makes me crazy...
@TheMattSturgeon
@TheMattSturgeon 6 ай бұрын
Glad that Java's "record" classes don't use verb prefixes on the generated getter methods... Record::thing is so much better than Record::getThing
@aviatedviewssound4798
@aviatedviewssound4798 6 ай бұрын
Wow never would I have thought that they were parallelizing workload this early into their engine since by this time a lot of developers were only using one CPU core to handle the whole draw calls and AI system.
@mattymerr701
@mattymerr701 6 ай бұрын
This is the first video where Flip's editing has been clear and noticably good
@TDarcos
@TDarcos Ай бұрын
I had an "Oh wow" moment sometime between 1976 and 1980 when I was reading the source to a player vs. computer game someone wrote, I don't know who. Player was 1, computer was 2, after each turn it switched. So how would I have done it? Probably with an if and 2 conditional assignments. The guy who wrote that program did much better, it in a way that was so beautiful I was stunned, just blown away. One line, one mathematical formula, it was *Player = 3 - Player* It is stunningly beautiful because it works perfectly. If player is 1 now it's 2; if player is 2, now it's 1. Absolutely amazing.
@un1kum42
@un1kum42 10 күн бұрын
I always do this even simpler. Player 1=0, Player 2 = 1 and your turn variable can be switched with "turn = turn XOR 1" and a 0 will become 1 and a 1 Wil become 0.
@ChannelSho
@ChannelSho 6 ай бұрын
The note around 19:34 about C++'s auto. I tried it for a while in a project, then realized it hides too much information. But what it was hiding was an unordered_map of types that were also pretty long (plus I needed the third argument to say how it's hashed), which was getting annoying to type, read, etc. But then I remembered, oh yeah, you can alias "data types" (for lack of a better term). So I went and did that. Made the code much more easier to read without losing information about what kind of data is being stored.
@meneldal
@meneldal 2 ай бұрын
With modern C++ you rarely need `auto` outside of lambdas (and even then you'd typically avoid storing them and just pass them as parameters). Most loops on containers can be replaced by something in stl algorithms, often something like reduce or transform_reduce. Then it's really hard to mess up indices and compilers are pretty good at optimizing this now.
@santifocus7432
@santifocus7432 6 ай бұрын
I cant side with Prime on the GetLength vs Length naming argument. Because a function with a return type is something that you Call/Invoke in other words you are "Doing" something in comparison to a field which you access. A field being named "Length" is totally fine because all you do is access it and that is all that happens. When you call a function with a return type you imply logic, if you imply logic you should phrase it as such, in other words it should be "GetLength" implying that you are getting something which might require some more complex logic to be done in contrast to just accessing something. The one special case is properties having get; set; functions, they are in the middle of fields and methods, they should be named like a field but treated as functions, which is why properties are not my favourite because sometimes they just have a backing field and do some minor logic if at all any and sometimes that do statechecks call 17 different methods and then return a value that has been calculated in a cumbersome way, have fun finding out that the reason why your game is running at 12 fps is because you accessed a property every frame instead of caching it because you assumed its just a simple getter.
@MGMan37
@MGMan37 6 ай бұрын
I kinda think not using 'set/get" solves the problem in your last paragraph. You can omit it for things which are trivial calculations (like length) but then use get/set/some other verb when it is a more intensive task to get that result.
@f1am3d
@f1am3d 6 ай бұрын
6:57 May we know - where did you get this from? In JS you can also make in/out parameters, only out parameters cannot be primitive types because of language peculiarities (they are passed as copies of values, there is no way to create a pointer), but otherwise the principle is the same.
@SwizZLe333
@SwizZLe333 15 күн бұрын
Prompt Engineering Guide Right Here People...Take Notes!!! @ 4:30 honestly...the whole thing is informative, useful and down right interesting! I'm gonna pull this transcript and plug it into my models and spit out a prompt to run this whole Videos thought process: UPDATE COMING SOON!
@code-dredd
@code-dredd 19 күн бұрын
People who argue for not "wasting" vertical space are also the same people who'd complain if they had to read an essay or article that had been written as a big wall-o-text instead of placing different ideas in different paragraphs.
@theodorealenas3171
@theodorealenas3171 6 ай бұрын
Sometimes I try to avoid squiggly braces in a general area as a trophy for abstracting the code. I'm still experimenting with abstractions and I don't know how to handle them, but on higher level code, I want it to look like a table of contents, and I want so little code that it shouldn't need a squiggly brace. But maybe I'll quit writing such code one day. I don't know.
@TheTrienco
@TheTrienco 6 ай бұрын
I had to check the date on the article, since some points are a bit outdated: -Iterators: in modern C++, you barely see them. In fact, I get almost annoyed in the rare cases I have to actually use them. ranges/views make a lot of things easier and cleaner. Even the algorithms are finally usable enough to justify not writing your own loop (projections are a big part of that). For example: ranges::find(device_list, index, &Device::index); Much nicer than before, where you had to use find_if and iterators: find_if(device_list.begin(), device_list.end(), [index](const auto& device){return device.index == index;}); -streams: thankfully we finally got print and println. And those insanely slow and clunky stringstreams can go die in a fire.
@infastin3795
@infastin3795 6 ай бұрын
Ranges are still painful to use. Especially if you did write some Rust code before going back to C++.
@TheTrienco
@TheTrienco 6 ай бұрын
@@infastin3795 They could be more elegant and the namespaces make it less than ideal (spamming "using" on everything is not always an option). But since I lack the direct comparison, do you have an example for Rust vs C++ in dealing with ranges?
@infastin3795
@infastin3795 6 ай бұрын
@@TheTrienco KZbin keeps deleting my reply. Working with ranges in Rust is just a lot less verbose compared to C++, but they are basically the same.
@infastin3795
@infastin3795 6 ай бұрын
@@TheTrienco Prime has watched some video with comparison between C++ and Rust, you can easily find it
@subcitizen2012
@subcitizen2012 4 ай бұрын
I'm not a programmer or coder, but I can appreciate it. I seem to recall that Doom 3 was in development for a relatively long time for the time. I remember an interview with someone saying they spent a long time working on the then-state of the art shadow mechanics. Elegant game though for sure, haven't fired it up in years at this point, played it a lot for a platformer, was a staple as soon as the Halo games felt too dated. I enjoyed some mods with it and reminiscing on that stellar Doom experience before it got too cheesey with modern mechanics. And I seem to recall as well - only vaguely without looking it up - that Doom 3 was the last Id-only release. They started getting bought up after that I think, and wasn't long before whats-his-name went to meta to work on Oculus.
@simonzuluaga2081
@simonzuluaga2081 6 ай бұрын
This one is so good dude, amazing video and article
@rakodoza7601
@rakodoza7601 5 ай бұрын
Fabien Sanglard is an amazing writer! I strongly recommend buying his books. He only have 3, I have read two so far but these are pure gold. The guy is one of its kind. (Like PrimeTime ofc ;) )
@skaruts
@skaruts 6 ай бұрын
Walls of text without empty lines between chunks is the worst thing ever. Even worse than 2-space tabs. I really can't understand how some people can work with it, because to me it's terribly confusing to even look at, let alone read. If things are separated, you look at it and you instantly get a sort of silhouette of the code, where you can already identify some of the loops, conditionals, definitions, etc. If it's just a jumbled wall of text, you'll have squint and decipher it line by line.
@MadsonOnTheWeb
@MadsonOnTheWeb 6 ай бұрын
About vertical spaces it depends. If the language I'm working on has clear code blocks like {} it is fine doing everything together. My mind is trained to read that. But if not like in python, just add vertical spaces. Overall I don't like to waste vertical spaces but I do use vertical spaces if I feel it is needed
@XavierChanth
@XavierChanth 6 ай бұрын
18:30 I make an exception when it's a guard clause, this is the only time I will do an inline if statement: if(shouldNotRun) return;
@thisbridgehascables
@thisbridgehascables 6 ай бұрын
I’m a space Andy for sure. I like to group lines that makes sense and add space where things change or before the function ends.
@khatdubell
@khatdubell 6 ай бұрын
If you hate white space, buy a bigger monitor. If you still hate it, buy a wider monitor and turn it sideways. I use lots of white space.
@RandomGeometryDashStuff
@RandomGeometryDashStuff 6 ай бұрын
07:10 you need memory address as parameter in c, there is no special syntax for out parameters unlike freepascal
@meneldal
@meneldal 2 ай бұрын
Tuple of return values?
@valseedian
@valseedian 4 ай бұрын
const isn't a default for most c like systems for local stack and heap variables because in the old days of you were using an imutable value you'd use a global or preprocessor directive to insert the literal. in reality, practically every system (I've ever used) treats all non-local values as locally const- that's why you need to pass values in by reference (or pointer...) if you intend for alterations in one scope to affect the calling scope directly.. I'm of the school that values shouldn't be const unless they cant be changed or shouldn't be changed for the duration of the scope for some reason. not passing by reference says "im not changing this", passing something as const says "this shouldn't be changed" anything defined as const in a local scope should be just be a literal. when a performance advantage is shown(not in js) I'll maybe change my mind.
@trapexit
@trapexit 6 ай бұрын
A vector iterator is really just a pointer. The abstraction makes it look like more than it is.
@40wattstudio41
@40wattstudio41 6 ай бұрын
I program in QB64PE (a version of QBasic) and I still found this video very useful. Very fast and entertaining 40 minutes!
@mater5930
@mater5930 15 күн бұрын
Every video, half of what you talk about goes over my head but I can't stop watching.
@ryonagana
@ryonagana 6 ай бұрын
i was a Quake II player in the 2000's and started my interest of programming when i read the Quake II's source code for the first time and i could understand the basics of the meaning of that code and what that does, and i built quake 2 from the source code using visual studio 6.0 and changing strings some texts with my name.. i had no experience in programmming, my first programming contact was BASIC and Delphi before that after this experience i just love C and C++ now i love read games source code.. but some of them are impossible to read (descent II and duke nukem 3d)
@Wobbothe3rd
@Wobbothe3rd 6 ай бұрын
Quake 2 has one of the very best (and last) software renderers EVER.
@MrYks123
@MrYks123 5 ай бұрын
Prodcast is great as always ... i just have one question .. is the Moustach real or u use it to give a mature feel to these analysis ?
@ErnestoStaccolanana
@ErnestoStaccolanana Ай бұрын
15:47 totally relatable... the importance of spacing (and I'd also say vertical alignment) is underrated
@pup4301
@pup4301 6 ай бұрын
I seperate all of my programming patterns, data types and data type accessories (like traits and impls) in their own files. Plus I only use the "use" syntax for traits because I have too. This help the code be self documenting. I also make info files for all files describing what happens in them.
@and_I_am_Life_the_fixer_of_all
@and_I_am_Life_the_fixer_of_all 6 ай бұрын
sometimes i like minimalism in my code, gets less overwhelming
@pup4301
@pup4301 6 ай бұрын
@@and_I_am_Life_the_fixer_of_all Thats okay. I just think knowing how to make maps for navigating your code and explaining it to others is a skill all unto itself.
@jubibi390
@jubibi390 10 күн бұрын
what's a latter style programming that was mentioned in 14:58?
@StevenAtkinson1988
@StevenAtkinson1988 4 ай бұрын
My neck is sore from all the nodding I've been doing while watching this video 😅. It is amazing how many useful ideas (and changes in your own coding behaviour) come from reading other people's source code - more so on codebases that have a large number of contributors.
@k-yo
@k-yo 6 ай бұрын
That dude not considering himself a programmer is either a blatant case of impostor syndrome, or I'm a dumb ass incompetent potato.
@user-og6hl6lv7p
@user-og6hl6lv7p 6 ай бұрын
He has some serious confidence issues for sure. Who tf programs for over 10 years and doesn't consider himself a programmer? Extreme modesty is infuriating at times.
@Finstaire
@Finstaire 6 ай бұрын
Back in the time this article really shifted the way I look at code. I'm not grateful enough to the author for what he did there. Nowadays, I still often reference this article to my colleagues when they ask for my views, even if I don't write c++ anymore it still feel relevant.
@skilz8098
@skilz8098 6 ай бұрын
If you want to see well organized and structured code, check out the GLM math library which is a header only library that is designed with the intent to match the primitives of OpenGL's GLSL shader language which is a C-like language. This is a beautiful linear algebra library to use. Now if you need something a little more efficient and or powerful then that's where the power of Eigen comes in. It's structured and written just as nice... Reading through their source code is not all that difficult to parse through. They're much easier than reading through either the STL or even many of the underlying Windows API, DLL driver hell... lol!!!
@spdcrzy
@spdcrzy 6 ай бұрын
DLLs and drivers give me nightmares as a risk analyst.
@Wobbothe3rd
@Wobbothe3rd 6 ай бұрын
@@spdcrzy don't play any Quake 2 mods ;)
@FrostsorrowGaming
@FrostsorrowGaming 3 ай бұрын
working in a support role where I had to review what our customers custom interface was doing, comments in code was a godsend. I can't imagine not having comments available.
@cas1652
@cas1652 6 ай бұрын
I really like you and I think your stuff is cool. I want to give you feedback but I don't want to be mean / flamy. It's just that when you read an article there are way too many slip ups. It's driving me crazy. Would you consider training a model on your voice and use that to read the articles?
@KangoV
@KangoV 6 ай бұрын
Every Java function i have ever written (in 20 years) has the parameters as input only. I'd scream if I saw another dev mutating the state of an incoming parameter. Fun fact, "const" is a reserved word in Java. I really wish it could be put to use for this reason.
@baguettedad
@baguettedad 6 ай бұрын
You say idPlane I say idPlane We are not the same
@MikkoRantalainen
@MikkoRantalainen 22 күн бұрын
We have a rule for our team that you have to document all public methods for a class. You don't need to write title line if the function name is descriptive enough but you have to document non-trivial arguments and you have to define the return value accurately. If you don't like writing documentation, try to mark methods as private as much as possible. The idea of documenting the public interface is similar to design-by-contract in Eiffel language. Without documenting the expected behavior in human readable form, you cannot know how the method should be fixed in the future when you hit some case it cannot handle correctly. Nobody expects you to comment individual lines unless those are a workaround for some external component. In that case, you should document why the workaround exists and why it works because that behavior depends on external component and if the external component ever changes, you need those comments to understand the change in behavior. And if you write any kind of workarounds, try to do feature detection instead of checking for version numbers to decide if the workaround should be applied or not.
@The1RandomFool
@The1RandomFool 6 ай бұрын
During Star Citizen's development they showed some source code in videos called Bug Smashers. I'm no expert by any means, and am simply average with no formal education. I saw a few things in there that made me see just how absurdly complicated the simplest things could be. It makes me glad I don't do any actual game development.
@katanasteel
@katanasteel 6 ай бұрын
Looping over iterators was basically replaced with the ranged for syntax in c++11
@Herkan97
@Herkan97 4 күн бұрын
14:53 - Is there supposed to be an image where he says "like this" in the article?
@TheTanglingTreats
@TheTanglingTreats 2 ай бұрын
Beautiful code is like fine art paintings. You get a range of cubism, realism and impressionism et al that different people gravitate towards
@mattymerr701
@mattymerr701 6 ай бұрын
I agree, C langs should make variables const by default because otherwise your source code ends up being 50% const anyway
@justingolden87
@justingolden87 6 ай бұрын
I like in theory the concept of either having inputs or outputs but not both, but what if you have a utility function designed to modify an object, such as sort it?
@ThePrimeTimeagen
@ThePrimeTimeagen 6 ай бұрын
this is a great observation and i think you are very correct on this
@MGMan37
@MGMan37 6 ай бұрын
If it's an inplace sort it can be denoted in the name and from that it is pretty obvious that it does both. Otherwise a sort could return a new list that is the sorted version.
@i.a.m2413
@i.a.m2413 5 ай бұрын
Team Vertical Space!
@christopherfreeman2858
@christopherfreeman2858 3 ай бұрын
I come from java, I've always had terrible experiences dealing with c++, but somehow it's getting better. Java is and was very reliable to me because the IDE paired with it let me have an easier time. I still have a huge lack of understanding in c++, and mostly in java, but in java there was way less entropy. I could write the specified code I found online, added my tweaks to it, and once the compiler and I sorted out our differences for 3 minutes, then I got to see how well my code is actually performing. In c++, the compiler just shook it's head after every hurdle I felt I overcame. I could never tell how to solve a specific problem, but now it's that same dance with more interesting complications, which is a good thing. That'll be fixed in due time.
@masplacasmaschicas6155
@masplacasmaschicas6155 6 ай бұрын
I only use pandas scikit tensorflow and keras for data analysis and ML so most of the time I have no idea what’s going on when talking about other languages than python or sql but primegean is just too entertaining
@dustmighte
@dustmighte 6 ай бұрын
15:38 adhd rubyist here and I'm very adamantly pro vertical space - vertical rhythm like Prime points out here is one of the most elementary ways to separate ideas and if your code doesn't use it I automatically nonparse it as "blur, complicated, ignore"
@Hersatz
@Hersatz 6 ай бұрын
"I am not a programmer" "I programmed for more than 10 years with the latter style" Them humble braggers are killing me. One cannot demonstrate advanced understanding of a subject and call himself "not a Foo-er". They just look like assholes to people with a lesser understanding of the subject who work their ass off to get even near that level of comprehension.
@Starshine777
@Starshine777 3 ай бұрын
36:57 "it's when someone solves a problem so different from me, it feels like I've unlocked a new way to solve a problem in my brain; has anyone ever had that?" yes! doing tech support where I had to debug code revealed a lot more insights about how to write good code than it did derps about bad code. and that got me into writing code
@Starshine777
@Starshine777 3 ай бұрын
I didn't have any "pro-gasms" though. Well, maybe from my own code when I came up with something tight. Well, low-level code for graphics is a lot more complicated than database operations for some clear human-defined use case so I guess I still have a lot to learn.
@stavinke
@stavinke 6 ай бұрын
Beautify?
@DeusGladiorum
@DeusGladiorum 6 ай бұрын
Output parameters are sometimes used in JS. Just have a function accept an object, and have it return that same object, mutated with a new property containing whatever you want
@malkeir9781
@malkeir9781 6 ай бұрын
haha "mutated" the input. Good one.
@malkeir9781
@malkeir9781 6 ай бұрын
Assuming this is trolling but if not, try `const foo = { val: '1' } as const` and then give your mutation a try. The principle of const is to create immutable objects (js only does this with `as const`). This isn't actually a good way to do it. JS is just annoying for not having immutable data.
@DeusGladiorum
@DeusGladiorum 6 ай бұрын
@@malkeir9781 I don’t understand what you’re talking about? You’re mocking the idea of the input being mutated, but then saying JS is annoying for not having immutable data? ???
@malkeir9781
@malkeir9781 6 ай бұрын
⁠@@DeusGladiorum I’m talking about not mutating input data. Immutable data enforces this. You can kind of do this with “as cont”. In practice if you were going to return an updated input you would take a deep copy of it, then return the copy with updated values. deep copy in js is generally done with stringify -> parse.
@malkeir9781
@malkeir9781 6 ай бұрын
It stops people using void functions to mutate objects. Or even writing a function that can somehow mutate the input object in memory while possibly returning something else.
@BozCoding
@BozCoding 6 ай бұрын
Lol, I threw away (recycled) my "Clean Code" book, because I don't even want someone to find it in a 2nd hand store :D
@jfftck
@jfftck 6 ай бұрын
In Firefox you can use the reading mode to remove styles from the page.
@aidanbrumsickle
@aidanbrumsickle 3 ай бұрын
Whether a function should have a verb name or not I think comes down to how you think about it. If a function is basically a computed property and the computation is simple / cheap, then just call it the thing. You wouldn't write a math library with functions like getSine() or raiseToPower(). Otherwise, I think it can be useful if the context requires it to clarify how a function gets its value: getFoo() - I don't know much about where foo comes from, but ideally it's not a heavy operation. fetchFoo() - a network is involved loadFoo() - a database or maybe filesystem is involved calcFoo() - a non-trivial calculation either in computational or cyclomatic complexity is involved You might pair these functions with a facade that does caching or lazy loading, and I think that in that case it can depend on context whether a simple getFoo() is preferred, or getFooUsingCache() or lazyLoadFoo(). For factory functions, it depends on whether your language has separate namespaces for functions and variables. In Java I could do `Person person = person("Tom", "Smith", 27)`. But in JS or Python, i would go for makePerson() or buildPerson() or maybe newPerson(). Another exception is what at least in Java are often called fluid interfaces, for example builder patterns like Person.builder().firstName("Fred").lastName("Jones").age(17).build(). These are making up for a lack of expressiveness in the language. Other languages would simply use keyword / named parameters or initializer literals.
@jfftck
@jfftck 6 ай бұрын
I feel like function definitions in video on KZbin about advanced TypeScript are just like the template function definition example in this article.
@nicholastheninth
@nicholastheninth 6 ай бұрын
I use comments to explain why I did something differently, mainly because Visual Studio’s Intellisense has neither intelligence nor sense, and it logs a lot of false-positives errors that force me to do something a different way to prevent false error cascade. It’s that and also some cases where I did some cursed things such as const_cast and mention why it is the way it is.
@1337GameDev
@1337GameDev 6 ай бұрын
36:33 - I actually like the VERB when it's not a field / directly modifiable (eg: private backing field). If it's essentially public, "get" makes no sense (eg: no compute needed for get/set). If computation is needed, adding the "get" makes sense, as it implies an ACTION is being done which could come at a penalty -- especially common in abstractions of a data source for IO
@Weaseldog2001
@Weaseldog2001 5 ай бұрын
That first item about how a function should do one thing... It comes down to a rule i was taught back in the days of the dinosaurs. There is no such number as 2. There is zero, one and many. It is easy to support the last three. But if you decide to support two, then you'll be asked to support three. Then four, etc... Code gets complicated as you add support for more and more single item tasks. IOf you start off supporting many, then going from two, to three, to four, is already built in. I'm currently working on a code base where previous engineers believed that a function should have many jobs. So we have functions with over a thousand lines of code, filled with loops, nested loops, switch statements, and generically named variables, that are reused over and over.. It is a nightmare to support. it is difficult to know if a small change here or there, will have unexpected results somewhere else. If you don't put limits on the complexity of your functions, this is what you get. Once you adopt the concept of one function one task, and one object one resource, everything starts falling into an easy to understand hierarchy.
@3ventic
@3ventic 6 ай бұрын
10:30 Regarding teachers or professors requiring you to comment every line of code as a student, I think it makes sense. Comments in real software exist for the developers and future maintainers to understand and work with the code and good code should need very few of them, but when you're a student the comments are for an entirely different purpose: for your teacher to be able to evaluate /your understanding/ of the code you're writing.
@sleepyinseattle4615
@sleepyinseattle4615 6 ай бұрын
No way! Indefensible… universities are teaching exactly the wrong habits
@spankyjeffro5320
@spankyjeffro5320 5 ай бұрын
Comments are mandatory even as a senior dev. You want the code to be as easy to read as possible. So, if a line of code is not instantly recognisable it mandates a comment.
@williams.7314
@williams.7314 6 ай бұрын
Does anyone have a link to the idTech 4 coding standards? I did a quick google search but didn't come up with anything promising.
@vinniciusrosa8284
@vinniciusrosa8284 6 ай бұрын
John Carmack creates his code thinking on how memory and cpu will deal with things. Some programmers nowadays tends to think more about wich library I will use to solve a problem without even understand what is happening. I like how John Carmack divides the program in little tasks, so ucp can breath while OS deal with memory alloc.... My style of code is similar, but I am not john carmack :( :D
@bunnyninjaface
@bunnyninjaface 8 күн бұрын
i thought i was clicking on a video about dooms source code, not some dude reading an entire kotaku article out loud jesus christ
@sleepyinseattle4615
@sleepyinseattle4615 6 ай бұрын
This was mostly about stylistic decisions but real beautiful code is when the solution perfectly matches problem
@nevokrien95
@nevokrien95 6 ай бұрын
One of my favorite use of comments is linking sources. Like oh this shit is done that way cause in source X they said that's a good idea
@KX36
@KX36 6 ай бұрын
when you're excited to have a floater but you check and it's not a floater....
@rem_0
@rem_0 2 ай бұрын
5:25 "// I'm sorry, they were rushing me" in chat is so true 😂😭
@guiguiregismercer5720
@guiguiregismercer5720 6 күн бұрын
I too have felt in awe of a beating written code. It’s really something special, I read a line of code that made me laugh once. A genius laugh, like a funny joke
@Kevin-jb2pv
@Kevin-jb2pv 10 күн бұрын
I love how the blog post gushing over the beauty ofJohn Carmack's** code is caught in an absolute fucking chaos storm of broken CSS and HTML that can't stop shitting itself long enough for Prime to get a complete thought out about it. **and others, but we all know anything he didn't personally write was still written according to his design philosophy and standards
@williamrgrant
@williamrgrant 2 ай бұрын
4:00 I love the realistic take here that code can be beautiful at solving a problem, but you think it's garbage if you don't understand the problem. As software engineers, we have to check ourselves when encountering new code bases. There is a weird tendency to think unfamiliar code sucks.
@hansfranz1069
@hansfranz1069 6 ай бұрын
European version of Dyad is written in C# using VSCode ... and it's awesome.
@pavlinggeorgiev
@pavlinggeorgiev 6 ай бұрын
Dyad.... now with less meth !
@CallousCoder
@CallousCoder 6 ай бұрын
@@pavlinggeorgievless fentanyl, that caused the zombie apocalypse in the US and Canada.
@IvanOdintsoff
@IvanOdintsoff 6 ай бұрын
Man, C# is so underrated and overhated. You can right some damn clean code with it.
@CallousCoder
@CallousCoder 6 ай бұрын
@@IvanOdintsoff The language is nice, I like it but it is getting too big I find (too many ways to do things). And my main problem is the runtime that you need. Those .NET runtimes upgrades is frequently a hassle - and because the language changes so often, things often get deprecated and you need to fix that. So I wouldn’t use if myself. I tend to lean to C/C++, Rust and when Zig’s architecture is stable Zig. I already adore Zig.
@kuhluhOG
@kuhluhOG 6 ай бұрын
32:07 And that the amount of supported types is limited. But well, that's why std::format exists these days. Although tbf, actually implementing a formatter for your types is confusing.
@namewastaken360
@namewastaken360 6 ай бұрын
I'm just a dumb windows programmer who has his hands on the mouse most of the time, especially when reading code. I like vertical whitespace, I typically scroll the screen rather than mine my eyes more than a few lines. Also surrounding functions don't need to be seen at the same time, if I really want to look at two functions at once I'll put them side by side in my ide.
Have We Forgotten How To Program?? | Prime Reacts
22:53
ThePrimeTime
Рет қаралды 434 М.
Why Doom is Awesome: Binary Space Partitioning
26:25
ShreddedNerd
Рет қаралды 1 МЛН
Каха ограбил банк
01:00
К-Media
Рет қаралды 6 МЛН
The Noodle Picture Secret 😱 #shorts
00:35
Mr DegrEE
Рет қаралды 29 МЛН
Prime React: Fast Inverse Square Root - A Quake III Algorithm
30:19
ThePrimeTime
Рет қаралды 147 М.
Yandere Simulator Complete Source Code Analysis - Code Review
57:02
A closer look at the Super NES DOOM Source Code Release | MVG
13:49
Modern Vintage Gamer
Рет қаралды 729 М.
They got away with this??
1:21:04
ThePrimeTime
Рет қаралды 1,2 МЛН
Factorio teaches you software engineering, seriously.
21:27
Tony Zhu
Рет қаралды 1,3 МЛН
The Unhinged Nature of GTA V Source Code
2:16
kpjVideo
Рет қаралды 1 МЛН
So You Think You Know Git - FOSDEM 2024
47:00
GitButler
Рет қаралды 992 М.
Doom engine - Limited but still 3D
6:57
borogk
Рет қаралды 526 М.
Quake In 13kb Of Javascript
57:13
ThePrimeTime
Рет қаралды 119 М.
The Worst Kind Of Programmer
19:15
ThePrimeTime
Рет қаралды 422 М.
WWDC 2024 - June 10 | Apple
1:43:37
Apple
Рет қаралды 10 МЛН
Samsung S24 Ultra professional shooting kit #shorts
0:12
Photographer Army
Рет қаралды 25 МЛН
TOP-18 ФИШЕК iOS 18
17:09
Wylsacom
Рет қаралды 807 М.
Нашел еще 70+ нововведений в iOS 18!
11:04
DC Fast 🏃‍♂️ Mobile 📱 Charger
0:42
Tech Official
Рет қаралды 485 М.