Тёмный

The Beauty Of Doom 3 Source Code 

ThePrimeTime
Подписаться 457 тыс.
Просмотров 452 тыс.
50% 1

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

Наука

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

 

24 ноя 2023

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 577   
@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 5 месяцев назад
"I'm trying to make Quake in Haskell btw, for fun btw, on ipad on the go btw" -John Carmack
@Wobbothe3rd
@Wobbothe3rd 5 месяцев назад
Carmack wrote a detailed post on Functional programming, its on facebook still.
@MrSlowestD16
@MrSlowestD16 5 месяцев назад
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).
@lordfrz9339
@lordfrz9339 2 месяца назад
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 5 дней назад
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 5 дней назад
@@alexale5488 I know the type of people, super annoying lol.
@ZM-dm3jg
@ZM-dm3jg 4 дня назад
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 3 дня назад
@@lordfrz9339 Some guys reaaaaaally love pissing contests. I think we all know a couple of these, lol
@Grumpicles
@Grumpicles 2 дня назад
​@@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.
@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. ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-bfbbS3LTCZY.html
@NeoShameMan
@NeoShameMan 6 месяцев назад
Chat gpt: exist
@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 5 месяцев назад
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 Месяц назад
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.
@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.
@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 5 месяцев назад
Nobody uses htmx bro
@spankyjeffro5320
@spankyjeffro5320 5 месяцев назад
Nope. Commas and other forms of proper punctuation are always mandatory. No exceptions.
@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 5 месяцев назад
@@MrHaggyy there's actually a id software coding style guide that essentially says this. It's linked in the article reviewed here.
@iLLuzion1st
@iLLuzion1st 3 дня назад
Check out the open source project: Open Tournament
@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.
@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`
@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.
@robwalker4653
@robwalker4653 4 месяца назад
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 3 дня назад
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.
@SkywalkerWroc
@SkywalkerWroc 5 месяцев назад
"If your code definition takes more space than body, you probably left the path of good programming" TypeScript: 👀👀👀
@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.
@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.
@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.
@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.
@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.
@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.
@Tabu11211
@Tabu11211 6 месяцев назад
logical code blocks gang. Love to bunch things together that are related and then leave a space before the next thing.
@mattymerr701
@mattymerr701 6 месяцев назад
This is the first video where Flip's editing has been clear and noticably good
@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.
@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 5 месяцев назад
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.
@f1am3d
@f1am3d 5 месяцев назад
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.
@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.
@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
@ryanleemartin7758
@ryanleemartin7758 6 месяцев назад
"hair is slowly turning blue from the roots". gottem! Good shit.
@simonzuluaga2081
@simonzuluaga2081 6 месяцев назад
This one is so good dude, amazing video and article
@mater5930
@mater5930 2 дня назад
Every video, half of what you talk about goes over my head but I can't stop watching.
@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.
@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 RU-vid 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
@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 ?
@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.
@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.
@trapexit
@trapexit 6 месяцев назад
A vector iterator is really just a pointer. The abstraction makes it look like more than it is.
@i.a.m2413
@i.a.m2413 5 месяцев назад
Team Vertical Space!
@jfftck
@jfftck 6 месяцев назад
In Firefox you can use the reading mode to remove styles from the page.
@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.
@subcitizen2012
@subcitizen2012 3 месяца назад
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.
@netslayeruk
@netslayeruk 6 месяцев назад
Woah who are you man? Popped out of nowhere on my feed this was very useful gamedev commentary, thank you!
@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 Месяц назад
Tuple of return values?
@ChannelSho
@ChannelSho 5 месяцев назад
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 Месяц назад
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.
@ErnestoStaccolanana
@ErnestoStaccolanana 26 дней назад
15:47 totally relatable... the importance of spacing (and I'd also say vertical alignment) is underrated
@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
@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.
@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
@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.
@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
@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.
@katanasteel
@katanasteel 6 месяцев назад
Looping over iterators was basically replaced with the ranged for syntax in c++11
@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 5 месяцев назад
Quake 2 has one of the very best (and last) software renderers EVER.
@MikkoRantalainen
@MikkoRantalainen 9 дней назад
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.
@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 ;) )
@mattymerr701
@mattymerr701 6 месяцев назад
I agree, C langs should make variables const by default because otherwise your source code ends up being 50% const anyway
@jfftck
@jfftck 6 месяцев назад
I feel like function definitions in video on RU-vid about advanced TypeScript are just like the template function definition example in this article.
@stavinke
@stavinke 6 месяцев назад
Beautify?
@teasysneeze
@teasysneeze Месяц назад
agreed, immutable by default is the rust hill I am most prepared to die on.
@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;
@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.
@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.
@aidanbrumsickle
@aidanbrumsickle 2 месяца назад
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.
@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.
@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!
@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.
@SwizZLe333
@SwizZLe333 День назад
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!
@GfxWakeup
@GfxWakeup 23 дня назад
What is this ,,Effective C++ book"? Is it Effective C++ by Scott Meyers? Thank you!
@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"
@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.
@sleepyinseattle4615
@sleepyinseattle4615 5 месяцев назад
This was mostly about stylistic decisions but real beautiful code is when the solution perfectly matches problem
@briankarcher8338
@briankarcher8338 5 месяцев назад
What makes menus in games extraordinarily difficult and bug-ridden is that you have three different states that need to all be active and live in harmony. Keyboard input, joystick, and mouse. An example: Typically when using a mouse, when you move the mouse cursor over a button it highlights the button. When you move the mouse off the button the highlight disappears. Joystick and keyboards are the opposite. J+K always need a button highlighted. So what do you do when somebody is navigating the menu with their joystick and the mouse inexplicably moves? Or the opposite, what do you do when the user mouse hovers over a button, then presses down on the joystick? It's a million edge cases and you have to pick the least bug-ridden path.
@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 5 месяцев назад
DLLs and drivers give me nightmares as a risk analyst.
@Wobbothe3rd
@Wobbothe3rd 5 месяцев назад
@@spdcrzy don't play any Quake 2 mods ;)
@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.
@Xtr33mm
@Xtr33mm 25 дней назад
are we still limited by DirectX in windows to provide all interfaces to hardware
@NathanaelNewton
@NathanaelNewton 20 дней назад
27:00 Oh no.. I feel attacked.. why are you looking at me 😂😂😂😂
@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.
@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
@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.
@thiernodia5785
@thiernodia5785 2 месяца назад
what theme does he uses?
@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.
@baguettedad
@baguettedad 6 месяцев назад
You say idPlane I say idPlane We are not the same
@larry515
@larry515 6 месяцев назад
With today's large, high resolution, monitors I'm more of a fan of additional vertical spacing. I imagine in the Doom 3 era, screen real estate was more limited.
@theodorealenas3171
@theodorealenas3171 6 месяцев назад
I'm not a fan of this argument because I've seen people with very large font sizes, and I think to myself damn let's hope he can read with that. It seems like he needs it. Personally, I'm on a laptop, and if I split vertically I get 72 columns, which is exactly the old school screen size based off of punch cards, and if I split horizontally a little bit I get roughly as many lines as those monitors. So I don't fully get it. I get why one would want a bigger monitor, you can have additional stuff, but to disable other people so that the spacing looks nicer, just doesn't click to me.
@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.
@Starshine777
@Starshine777 2 месяца назад
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 2 месяца назад
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.
@MadsonOnTheWeb
@MadsonOnTheWeb 6 месяцев назад
Remember that the article's commentary person is not a programmer.
@1337GameDev
@1337GameDev 5 месяцев назад
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
@CarlosEstebanLopezJaramillo
@CarlosEstebanLopezJaramillo Месяц назад
I have code blocks, like I group variable definitions and related code, and then fold regions, dunno if it's a standard for IDEs or just VSCode that implements foldable regions with `// #region validation block` and `// #endregion`.
@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
@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
@SimGunther
@SimGunther 6 месяцев назад
Reading time combined with comprehension time would be the only quantitative measurements for how "beautiful" source code can be AFAIK.
@trappedcat3615
@trappedcat3615 6 месяцев назад
No code. Ultra Beauty.
@SimGunther
@SimGunther 6 месяцев назад
​@@trappedcat3615Do you even know what the "no-code" is doing without comments or documentation? 🤔
@trappedcat3615
@trappedcat3615 6 месяцев назад
@@SimGunther it requires one comment. // Let the team sleep in peace
@luigidabro
@luigidabro 3 месяца назад
My mindset is "make it const, so if you pass a const variable into it, it still compiles."
@vetiarvind
@vetiarvind 24 дня назад
I think you can read Carmack's blog from before 2014 (that's when I read it) which talks about pure functions.
@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.
@khatdubell
@khatdubell 6 месяцев назад
I hate it when people use typedefs to hide complex types.
@jobowobo6700
@jobowobo6700 4 месяца назад
Beautiful code, like all beautiful things, is in the eye of the beholder. You can describe its features, but you will only know it when you see it
@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?
@bripbrap
@bripbrap 4 месяца назад
36:40 I think it really depends, for me i much prefer `getLength` if its a method. however `length` if its a property.
Далее
The Most Amazing Software Ever Created
20:02
Просмотров 279 тыс.
Что за обновление в Tanks Blitz?
1:19:16
Make me the happiest man on earth... 🎁🥹
00:34
How I Cut GTA Online Loading Times By 70%
22:15
Просмотров 220 тыс.
They Turned off this GPU Factory For Me!
15:31
Просмотров 115 тыс.
How One Line of Code Almost Blew Up the Internet
13:47
Why Doom is Awesome: Binary Space Partitioning
26:25
You dont know OOP
50:48
Просмотров 274 тыс.
Carmack Doesn't Like Vim | Prime Reacts
26:52
Просмотров 373 тыс.
xz Exploit Is WILD - Must See Bash Part
1:20:46
Просмотров 298 тыс.
Fast Inverse Square Root - A Quake III Algorithm
20:08
😱НОУТБУК СОСЕДКИ😱
0:30
Просмотров 3,2 млн
ПК с Авито за 3000р
0:58
Просмотров 1,8 млн
Делаю деньги и кайфую
0:59
Просмотров 21 тыс.