Don't Write Comments | Prime Reacts

  • Опубликовано: 6 месяцев назад

    ThePrimeTimeThePrimeTime
    подписчиков: 245 тыс.

    Recorded live on twitch, GET IN
    / theprimeagen
    Original: • Don't Write Comments
    Author: / @codeaesthetic
    MY MAIN YT CHANNEL: Has well edited engineering videos
    / theprimeagen
    Discord
    / discord
    Have something for me to read or react to?: / theprimeagenreact

@XxDarkCinisterxX +606
@XxDarkCinisterxX

No wonder Tom didn't add comment support to JDSL. It's self explanatory. Tom is a genius.

6 месяцев назад
@whig01 +21
@whig01

This is another reason he should consider using TOML. No comment support.

6 месяцев назад
@MrHords +7
@MrHords

Fuckin lol 😂 Tom is a genius

6 месяцев назад
@uchennaofoma4624 +5
@uchennaofoma4624

Of course, Tom's a genius 😂😂😂

6 месяцев назад
@me-low-key
@me-low-key

Tom is a genius

6 месяцев назад
@user-gt2th3wz9c +2
@user-gt2th3wz9c

@@whig01 TOML is TOM's language?

6 месяцев назад
@thewizardsofthezoo5376 +362
@thewizardsofthezoo5376

I blame Scott for not explaining that comments weren't implemented in JDSL.

6 месяцев назад
@ThePrimeTimeagen +99
@ThePrimeTimeagen

Scott, the true villain in all of this...

6 месяцев назад
@fulconandroadcone9488 +15
@fulconandroadcone9488

@@ThePrimeTimeagen He was a visionary. A world where you don't need comments to navigate code. He invented JDSL to accomplish this goal, a true Genius.

6 месяцев назад
@Eric-vh4qg +7
@Eric-vh4qg

I agree that senior developers definitely should have made him aware of such a huge vulnerability. I also wonder how something like this was pushed to production. I thought the json metadata was calling for specific revisions of these methods, so you can always maintain backwards compatible dependencies; his changes shouldn't have effected production unless he updated all the metadata to point to his new revisions as well. If he changed so much stuff, why wasn't any of it reviewed? Seems like this company had really bad organizational issues, which allowed for a junior developer to make sweeping changes without oversight.

6 месяцев назад
@nachiketagrawal5154 +12
@nachiketagrawal5154

He should have written a comment in JDSL, explaining that comments are not supported But unfortunately he could not, since comments weren't supported

6 месяцев назад
@TheNewton +6
@TheNewton

He didn't have to implement them, it's a first class feature in the format he selected. Because he's a genius. { "comment": "this is a JSON comment ~Genius Scott" } The noob that didn't understand JDSL put the comments in the javascript.

6 месяцев назад
@pucku882 +642
@pucku882

I go a step further than not writing comments, I run it through an obfuscator before committing to the repository ♥

6 месяцев назад
@cmelgarejo +45
@cmelgarejo

Username checks out

6 месяцев назад
@pucku882 +62
@pucku882

@@cmelgarejo how dare you!

6 месяцев назад
@quantumimperfections2550 +10
@quantumimperfections2550

It's not often I actually laugh when I "lol" but this was one of those times. Thanks o7

6 месяцев назад
@MrLowbob +10
@MrLowbob

minifying is decent too. who doesnt like variables a..z, aa..zz, etc

6 месяцев назад
@ShrirajHegde +39
@ShrirajHegde

I just gitignore the source files and track binaries because at the end of the day, that's what matters most

6 месяцев назад
@TheTrienco +108
@TheTrienco

With the qualifier "most of the time", I absolutely agree. Just yesterday I was cursing my heart out, because code was changed to do the complete opposite of what the comments said. Nobody maintains them, half the time people don't even read them and it takes on average 2 weeks before "redundantly repeating what the code is telling me already" turns into "blatantly lying to my face".

6 месяцев назад
@herrpez +24
@herrpez

Why don't code reviews catch that? Odd. "Your comment here is useless. Report to the flogging station immediately." "This comment has nothing to do with this code. Flogging station." People would catch on eventually.

6 месяцев назад
@TheTrienco +14
@TheTrienco

@@herrpez I wonder if some of those useless comments can be blamed on certain teachers. I remember at university they told us "for each line of code, there should be one line of comment". You can guess what the result of that was...

6 месяцев назад
@grzegorzdomagala9929 +8
@grzegorzdomagala9929

This problem arises when people write in comments what the code does instead of what it should do. "Setting timeout to 5" is useless and potentially misleading "waiting till work process completes first cycle" is usefull - even if you change timeout to 15 or replace it with conditinal wait. Or even if someone "corrects" the code to oblivion - feature maintainer will know what you WANTED to achieve here. And personally - I just like to mark "difficult" parts of code with prayers to Omnissiah or Cthulhu :)

6 месяцев назад
@wetfloo +2
@wetfloo

​@@herrpezI guess because people don't look at lines that weren't changed, and if comments stay the same, that means there's nothing to look at At least that's how my brain works

2 месяца назад
@Mclfarm2
@Mclfarm2

Maintain them then?

Месяц назад
@Jschmuck8987 +39
@Jschmuck8987

This guy’s voice is awesome. Like, I never thought I’d be able to tolerate a voice like this but he’s even more hilarious because of it. I can’t get enough of his videos.

6 месяцев назад
@stefanms8803 +7
@stefanms8803

It's because he sounds like a cartoon character.

5 месяцев назад
@desertfish74
@desertfish74

@@stefanms8803 this is exactly it

5 месяцев назад
@notuxnobux +24
@notuxnobux

Linus torvalds said it well: Dont describe your code, describe why you are doing something (if it's not obvious). It's because otherwise the comment does the same thing as the code, so your code should be readable so you dont need comments. But sometimes you need to write code in a specific way for uncontrollable reasons (external issues such as driver issues, some external service behaving in a weird way, some library requiring something that is not obvious, etc).

6 месяцев назад
@mattmurphy7030 +7
@mattmurphy7030

My favorite is //hackity hack because it removes all doubt that what you’re seeing is bizarre

6 месяцев назад
@quantumimperfections2550 +33
@quantumimperfections2550

Real talk: I usually only put comments in code (be it JS, R, Python or SQL) when i am referencing a business rule that needs to be understood. Preferably simply listing the business document link so if code needs to be updated they can go in-depth as to 'why' something is the way it is. I've found this is a big help in research settings where government & sponsor rules and regulations shift ever so slightly quite often.

6 месяцев назад
@mattmurphy7030 +2
@mattmurphy7030

Extending that, I include references that I used if they were important to figuring out some code.

6 месяцев назад
@eyondev +4
@eyondev

@@mattmurphy7030 Another extension: Linking to Github Issues when you need a workaround for something that's currently not up to the documentation spec.

6 месяцев назад
@antdok9573
@antdok9573

This is why BDD test cases exist.

6 месяцев назад
@zactron1997 +57
@zactron1997

Rust is the first language where I felt like comments were right. The language is descriptive enough that I dont often need to write comments explaining what's happening. The built in testing system means I don't need to write comments explaining edge cases or intended use. Docstrings with tested examples are probably the best documentation I've ever seen in normal library code. Obviously other languages can avoid comments too, but in the looser or harder langauges I need comments more.

6 месяцев назад
@davidlanda2324
@davidlanda2324

Go!

6 месяцев назад
@KManAbout +2
@KManAbout

Doc strings are just comments

6 месяцев назад
@aoeu256
@aoeu256

docstrings come from LISP, types as comments comes from ML.

5 месяцев назад
@aoeu256 +1
@aoeu256

@@KManAbout Doctests will execute the tests in your doc strings. Tests can be nice as you can get chatGPT to implement your function for you from the tests, you could program your IDE to show you values flowing through your program from the tests, you can convert tests into types. However, make sure you are testing the properties of your function as they pertain to your business needs not the implementation details.

5 месяцев назад
@JesseRudolph +1
@JesseRudolph

I need comments in any environment where i might be 'in the process' of developing a solution to a problem, rather having already solved the whole thing in my head, and I am now just fleshing it out with the obvious and perfectly well behaved and well formed code structure that I have somehow worked out. Or in other words; code is a process. Bad code and bad non-code descriptions need to be possible to represent while you don't have perfect alternatives at hand. If I didn't have comments, I'd just have documents in my source tree referring to specific spans of coude in the source files that the document is talking about. Essentially, comments with a bunch of stupid extra steps. I do get the motivation behind this conclusion; you don't want your codebase to be littered with crippled code that needs comment crutches to make any sense. But at some point in the development process, you need to set this aside and write bad code. So you can get around to writing bettter code later.

4 месяца назад
@geoffreyzziwambazza7862 +9
@geoffreyzziwambazza7862

The math in his if statement example had me laughing 😂. And he did it so smoothly, that it doesn’t come off as inappropriate.

2 месяца назад
@tordjarv3802 +91
@tordjarv3802

The best comment I have ever seen in a code were: ! fiddle with variables and print stuff It was in a very old Fortran code for doing configuration interaction calculations for atomic nuclei.

6 месяцев назад
@ThePrimeTimeagen +26
@ThePrimeTimeagen

respect

6 месяцев назад
@anmoon +7
@anmoon

​@@ThePrimeTimeagen yes, it didn't blow up, respect. bet it was JDSL 😂

6 месяцев назад
@jayshartzer844 +6
@jayshartzer844

A comment that will remain accurate until the heat death of the universe 10/10 would compile again

6 месяцев назад
@luis10barbo +113
@luis10barbo

Nothing to add here, just let me state a fact... Tom is a Genius.

6 месяцев назад
@jaredmistretta3018 +7
@jaredmistretta3018

Oh is this gonna become a thing? I'm down.

6 месяцев назад
@kebien6020 +1
@kebien6020

@@jaredmistretta3018 Hi down, I'm up.

6 месяцев назад
@stanislawcronberg3271 +4
@stanislawcronberg3271

Watching ThePrimeagen instead of sitting down and coding is the real copium

3 месяца назад
@jl6723 +14
@jl6723

I am a fan of triple-slash comments in C#, my thought is that if you need a comment inline, it probably should be it’s own function and then inside the triple-slash I can detail what is being done, what are the concerns for the comments, and why did I decide to do this. It also allows me to explain concepts. It also can be used by auto-documentation tools to make documentation. And then there is a team effort to update and scrutinize the comments when we change things up such that people can better understand. Self-commenting code has been a nightmare to work with in the past, because evaluating decisions for refactors suck.

6 месяцев назад
@envo2199 +3
@envo2199

++ comments for methods are truly helping, and every library should use it. If a method doesnt have this intellisense comment, i always get a little angry.

6 месяцев назад
@Temari_Virus +6
@Temari_Virus

Honestly C#'s /// comments are less like comments, and more like in-source documentation. Heck, they evem appear in your tooltips!

6 месяцев назад
@jaysistar2711 +1
@jaysistar2711

These are called "doc comments", and I think that they originated in Java, which is a language that, like C#, I don't want to use for anything if I can help it, but the doc comments are a good idea, which is why Rust has them as well.

6 месяцев назад
@salvadorroibon +5
@salvadorroibon

Just watching this channel the last year made me a better programmer. Love you Prime, thank you

6 месяцев назад
@rsdyeahh +8
@rsdyeahh

Very nice, agree in most points. Now, try to write an assembly code with no comments and come back 6 months later

6 месяцев назад
@mattmurphy7030
@mattmurphy7030

That’s cheating

6 месяцев назад
@SimGunther +28
@SimGunther

I love how "Tom" the megamind genius is a recurring character in these stream highlights

6 месяцев назад
@woolfel +5
@woolfel

the comments should be about the design rational, the trade offs, business requirements and context. If you're writing a library that calls some other service, the comments should be about the quirks of the service and any odd stuff that you found. The comment should be about "how do I help someone maintain the code."

6 месяцев назад
@ismaelgoldsteck5974 +2
@ismaelgoldsteck5974

I like putting a "project philosophy" file into the documantation which gives a general idea of how the projects structure is intended to be. Explaining which services there are, how the code can be extended, etc.

6 месяцев назад
@OhsoLosoo +1
@OhsoLosoo

My first computer science teacher made us write out what our functions were going to do before we could code. We also had to put in the comments which function was calling which. It is actually easier to run my code through an anti comment program (just deletes any thing in a ‘’’ or after #) than to break this habit unfortunately.

3 месяца назад
@omega_no_commentary +29
@omega_no_commentary

If you can make your code readable enough and good enough, don't write comments. If you can't, Id rather have a commented steaming pile of garbage than a steaming pile of garbage with no comments at all.

6 месяцев назад
@epotnwarlock +11
@epotnwarlock

you feel forced to comment old/legacy code to hopefully guide the next sucker to greener pastures, also python is epic

6 месяцев назад
@kiryls1207 +3
@kiryls1207

you should know that Tom writes comments to comment other comments. that's why he's a genius

6 месяцев назад
@sutsuj6437 +200
@sutsuj6437

I think using comments as headers to segment areas of a large code blocks, is something useful. It allows quickly skimming through code, without having to read the whole thing.

6 месяцев назад
@Yotanido +57
@Yotanido

I will admit, I do sometimes do this. But this typically indicates that your function is doing too many things and should be split.

6 месяцев назад
@ybabts +16
@ybabts

If you have to write headers to segment your code, you either have functions that are much too l large or your file is way too large.

6 месяцев назад
@PeterAuto1 +1
@PeterAuto1

why not moving the sections into their own functions?

6 месяцев назад
@ScibbieGames +43
@ScibbieGames

​@@Yotanido if it's a bunch of things you only have to do once with no repetition, splitting it up is likely a waste of time.

6 месяцев назад
@MrLowbob +2
@MrLowbob

​@@ScibbieGames if you have such a big thing that you need to write segment comments, usually you could instead use the time to comment it to just split it into different files/classes in the first place and then wouldnt need the comment any more.

6 месяцев назад
@Anri17_ +24
@Anri17_

Comments are useful for writing down my thought process in the context of a piece of code. I find that it's better to just get things done as fast as possible, leave some comments describing and explaining the function and purpose of the code, then return at a later date with a fresh mind and refactor everything. It's kind of like writing an essay. Your first draft will usually be ugly, but it has all of the ideas that you want to deliver. It's only when you return to it later that you are able to edit it with better phrases, more appropriate words, a cleaner and more clear structure, add, or even restructure some of the ideas.

6 месяцев назад
@RigelOrionBeta +1
@RigelOrionBeta

This is exactly how half my comments are written for. Much of the time they help me quickly understand what I wrote a set of code to do, and honestly, if it's good enough for me to read in a month of not looking at it, it's probably good enough for others too.

6 месяцев назад
@davidp.7620
@davidp.7620

The problem comes when you never actually go back to it and you leave module after module of unmaintainable code

2 месяца назад
@Anri17_ +2
@Anri17_

@@davidp.7620 What are you talking about. Any change that needs to be made to the code becomes easier, because now you will have comments explaining purpose of the code and outlining other crucial details. If anything it makes code more maintainable.

2 месяца назад
@davidp.7620
@davidp.7620

@@Anri17_ as I said, assuming you ever have the time to go back to them

2 месяца назад
@rollin340
@rollin340

Glad I'm not alone in hating unclosed tags. I also despise code where some have the curly brackets, and some don't. I always prefer with, but to do both is insane.

29 дней назад
@incremental_failure +11
@incremental_failure

I've been struggling with a relatively short function as of late regarding datetime conversion and various adjustments with a dynamic axis. The code is commented a lot and it has taken me over a week to understand it. Functions and classes are intertwined, most variables are kept short for whatever reason, lists and dicts are unpacked into objects, functions are passed in init, of course no type hints (yes, it's python). A simple thing like using longer, easier to follow variable names would solve so much and dynamic typing is the absolute worst thing about python.

6 месяцев назад
@ThePrimeTimeagen +5
@ThePrimeTimeagen

me hates dynamic typing

6 месяцев назад
@incremental_failure +1
@incremental_failure

@@ThePrimeTimeagen Timing is perfect. Part of Cython compiled production code just failed for wrong typing as Cython has discipline regarding types. Tests written in Python let it slide.

6 месяцев назад
@PamellaCardoso-pp5tr
@PamellaCardoso-pp5tr

@@incremental_failure why do people don't stick with a rule on adding the types of stuff into the name of the variables/functions in python? like if it's a integer variable Int_x = 3 def Void_foo(Int_x): String_y = "something" wouldn't that make python usage less... shitty? i dunno cuz i abandoned writting in that mess of slow language and moved to zig and haskell instead. Monads go booooom babyyy

6 месяцев назад
@incremental_failure
@incremental_failure

@@PamellaCardoso-pp5tr And complex types? Python isn't that slow either since well, all the complicated stuff has Python only as a layer. If you depend on a dozen or more critical modules, switching languages fast is out of the question.

6 месяцев назад
@PamellaCardoso-pp5tr
@PamellaCardoso-pp5tr

​@@incremental_failure you can try to define interfaces using comments... i dunno man. i would do anything to keep some sort of sanity in my code, specially now that i learned the beauty of types through the category theory point of view and how types relate to each other. and yes, python is slow. you aren't using python, you're using C in disguise, and in that regard Mojo seems to be the thing that will make python less shitty to use, but it will still suck without having damn brackets

6 месяцев назад
@sonofabippi +2
@sonofabippi

As an embedded engineer, even if your comment is "this code is f'd-up" and at that point, even if it's a lie --- it's still a warning that it is not going to work like what you will work like what is epxected. That's huge. That's helpful. I worked with this stuff that was only very loosely embedded-to-JS, and copying it immediately via clone seemed silly --- but the comment saying, "this is f'd-up, I get it"... GOOD STUFF.

6 месяцев назад
@iFireender
@iFireender

One point: in embedded programming, sometimes comments are almost necessary. Writing some random number to some random register or similar can be very confusing otherwise. For example: Accessing the DRW register over SWD after setting a new address in the TAR register requires one dummy read first. So, you set the register you want to read from, and then you read twice. Without a comment in there, that seems like a bug. A simple //dummy read after the first read explains what happens.

5 месяцев назад
@ICEknightnine
@ICEknightnine

This made me realize that I have a bunch of, what would be considered, redundant code but I don't want to remove it because the human language helps me understand at a glance what the code is meant to do even if that can be surmised by reading the code itself. It also helps with bugfixes if the code doesn't do what the comment says it's supposed to do, the original intent is preserved (though that means I need to update comments when making changes).

5 месяцев назад
@fabricehategekimana5350
@fabricehategekimana5350

As always, your videos are incredible! 00:06:52 I think optionals came from the type theory (I think it's related to monads like those in haskell)

6 месяцев назад
@richardhunter132
@richardhunter132

when I was at college, the tutors always told us to add as many comments to the code as possible. at the time I assumed that was considered good practise, but now I realise it was because our code was so shitty, comments were the only way they could understand it

2 месяца назад
@edgeman1135
@edgeman1135

The problem is that you do get marked down for having few comments, but not for doing so excessively. Obsessively commenting is straight up optimal.

Месяц назад
@conorstewart2214 +2
@conorstewart2214

Maybe it’s just because I mainly do embedded programming, microcontrollers, FPGAs and similar, but comments are very useful sometimes and I would rather commented code than non commented code, if the comments don’t make sense you can always fall back to just reading the code.

5 месяцев назад
@Mclfarm2
@Mclfarm2

Probably the more complex your domain the more comments can be helpful.

Месяц назад
@Muaahaa +4
@Muaahaa

I was repurposing an old computer the other week. It is over 10 years old and has code from some of the projects I was doing while learning front-end dev. The comments I wrote in there killed me to read. Practically every block of code had a header like "// ---- Functions ----" or dumb stuff like that XD

6 месяцев назад
@mattmurphy7030 +2
@mattmurphy7030

Almost as bad as //increment the index

6 месяцев назад
@JoanGonzalezTrolloCat +2
@JoanGonzalezTrolloCat

damn u didn't have to call me out like that

6 месяцев назад
@EmperorFool +2
@EmperorFool

Don't write comments about "what" or "how". Instead, write clear code. But DO write comments about "why" when necessary.

6 месяцев назад
@wade__ +1
@wade__

I like using comments to jot down notes or to organize my thoughts tied to the surrounding code, but as I implement the notes/ideas, those comments get deleted because the code basically becomes the comment

6 месяцев назад
@simonfarre4907
@simonfarre4907

I've seen Primagen confuse borrow checker with allocation & deallocation twice now. Though this time he's somewhat closer to the truth than the last time; because unique_ptrs *does* involve life time management. You can still share a unique_ptr via reference arbitrarily.

6 месяцев назад
@maxmustermann3938
@maxmustermann3938

I agree... whether you comment "add 1 to x" or "compute the sum of the vector", the code already makes that obvious. But if you do some strange loop where you're adding +1 for indiscnernable reasons to some index and add a comment explaining how the data is layed out, that actually helps in understanding what's going on. Example I recently wrote, I had two loops, one going over odd indices, the other over even indices and they had a branch where some index was either i, i+1 or i-1 - you wouldn't know what the fuck is going on there without knowing the data layout, "positive" directions where stored at odd indices, with their corresponding negative direction stored +1 index away, and the algorithm implemented there required you to handle those separately and sometimes access those corresponding directions. It was all low-level CUDA code, so no super fancy abstractions. Comments are much more important when you really can't use abstractions like optional but *have* to work with just integers, low level data types and specific weird layouts and giving some weird meaning to specific values, like the -1 in the example. If you're implementing some very specific algorithm, a link to the paper or the name of that algorithm as a comment makes sense. Nobody knows what a fucking esoteric pull is supposed to be or how it works after all.

25 дней назад
@PieterJacob
@PieterJacob

I agree! I don't write comments that explain code. I write comments if my code is weird or violate a basic principle, like a query inside a loop, that explains why in that particular situation I had no other choice.

5 часов назад
@bimsherwood7006 +1
@bimsherwood7006

Naming things with the code is better than comments, because the compiler checks you. Actual comments can be plain wrong and you only figure it out after you've been confused. And that's the opposite of what the comment was for!

6 месяцев назад
@stashladki2594 +1
@stashladki2594

Can we all agree at that point that Prime is an actual AI?

6 месяцев назад
@_Aarius_
@_Aarius_

I use comments sparingly to explain the reason of a design, or a high level explanation of unobvious algorithms. Otherwise, most code should be self explanatory (with maybe documentation comments) Or to document an unexpected failure mode which may not be considered during future revisions otherwise

6 месяцев назад
@twiksify
@twiksify

Golang got a test suite which validates examples via code and expected output in a comment. These comments are later published in API docs along with the build

6 месяцев назад
@Rin-qj7zt
@Rin-qj7zt

i write comments to make notes to help me remember where i was and what i was thinking at the time. these are personal projects where i'm the only one i'm talking to. i find it helpful, so i keep doing it. if comments are helping, keep writing them. if they aren't, then stop. it's that simple.

6 месяцев назад
@JoshuaWise1994 +1
@JoshuaWise1994

I find comments that explain the code useful in two circumstances: 1. As a block comment at the top of a file, summarizing what the file does 2. Comments breaking up sections of a large procedural function that does several complicated steps. Many people will say "if you have several complicated steps, you should just split them into multiple named functions". But I disagree with this. When you split them into functions, you're implicitly saying "these functions can be called Independently, and perhaps in any order". But in the case of the large procedural function, each step must happen in a very specific order, and the steps shouldn't be invoked in isolation. Having them in order within a single encapsulated function is much better for expressing how it should be actually used, and comments can just help summarize what each complicated step is doing, and provides a little break between reading each section.

5 месяцев назад
@bearwolffish +4
@bearwolffish

I love when a dev explains what the code is (supposed to be) doing, makes it easier to audit the mistakes if the logic doesn't line up. Someone else being able to tell what your code is actually doing, and it doing what you think it does are two different things.

6 месяцев назад
@Spencer-wc6ew +1
@Spencer-wc6ew

Also not everyone thinks in the same way. Something may be so simple and obvious to you, but make no sense to another debeloper.

3 месяца назад
@TinBryn +1
@TinBryn

People read comments less than computers, because at least JDSL reads comments, Tom is a genius.

6 месяцев назад
@mattmurphy7030 +1
@mattmurphy7030

JDSL is arguably the only language sophisticated enough to include first-class comments

6 месяцев назад
@onionike4198
@onionike4198

I like to try to write code so that it describes itself clearly. When it doesn't I'll write a comment. I use variable names that are nouns or adjectives, function names that are verbs. All this with the intent that the code will read more like a book rather than arbitrary equations.

6 месяцев назад
@mdlamar
@mdlamar

Totally correct about specs being the program. Business people don't need engineers. Remember when they made Fortran and business people were suddenly able to write all their own code?

Месяц назад
@erroneum
@erroneum

Entirely too many people think about C++ as C with some features tacked on top, and so when they think about what C++ should look like, they think about C, but with a few extra things, like std::string. While this technically isn't wrong, it's also far from optimal. Much better is to think of C++ as a language in it's own right, which happens to also be mostly compatible with C source code, and to not assume that the C way to do things will serve you well. After all, C++ has things like std::unique_ptr and std::shared_ptr (which you can even specify custom deleters for, allowing self-managing resource handles (wrapping the C file API is a classic example); std::string_view, which allows for looking at a non-owning view of memory with a memory footprint of only a pointer and a std::size_t; and even things like the and which enable enable things that C would need a library to do at all (to say nothing of language level features like coroutines, templates, and standardized attributes).

6 месяцев назад
@ZantierTasa +9
@ZantierTasa

I just put short, simple numbers as comments, which refer to the SVN revision number where the full comment is stored. That way it's less distracting, but it's easy to checkout the comment if you're confused about how that particular JDSL function is working.

6 месяцев назад
@mattmurphy7030 +3
@mattmurphy7030

And that way all the comments that ever existed can be referred back to, nothing is ever lost!

6 месяцев назад
@mskiptr
@mskiptr

I feel like I've read a copypasta about it once

6 месяцев назад
@Yay295 +1
@Yay295

@@mattmurphy7030 "nothing is ever lost" until you migrate to Git

6 месяцев назад
@handsome_man69
@handsome_man69

lol

6 месяцев назад
@Fluid55
@Fluid55

Code Aesthetic is always one step ahead of The Start Up

6 месяцев назад
@Matt23488
@Matt23488

10:40 - Not all HTML tags require closing tags, and I'm not referring to self closing tags like . It goes back to the early days of the web, when you wanted to send as few bytes as possible over the wire. The HTML spec allows you to omit closing tags in some cases as the other rules in the spec prevent ambiguity. If you don't follow the spec of course, all bets are off. I saw some of your chat saying it's a new thing, this is false. It's always been the case.

21 день назад
@jacke6579 +1
@jacke6579

I work in a team where the majority of members have very little coding knowledge, or desire to learn. However, I write a number of Python scripts to support various tasks which occasionally need to be edited/slightly modified by other team members. In this situation are heavy use of comments the way to go? The ideal solution is to upskill the team, but that's never going to happen as the company doesn't hire for coding skills or enthusiasm, and as almost all coding guides (quite rightly) assume you work within a team competent in coding, I feel like they always need heavy adaption to be relevant.

6 месяцев назад
@trogdorstrngbd +2
@trogdorstrngbd

More comments are called for in this situation, especially in sections that you know will be frequently modified, but "heavy" commenting will just be counter-productive in the long run. It'll waste your time and give your coworkers an excuse to avoid reading/doing proper tutorials for coding.

6 месяцев назад
@muhwyndham
@muhwyndham

This is one of those situations where comment is justified. Hence "comment is bad **most of the time**" not "all of the time"

3 месяца назад
@-vis-2492
@-vis-2492

I am just wondering, If comments were not writent that bad how easy would it have been to train an AI to understand code ?

4 месяца назад
@tsitsimelody5874
@tsitsimelody5874

My guess is the optional types came from functional programming and haskell world, I remember learning them when i decided to learn functional programming

6 месяцев назад
@kattankarl
@kattankarl

I'd say the big exception to this if when you write code to integrate with an external system like a ERP system or something. Having a few comments instead of being forced to spelunk ERP documentation to understand why some seemingly pointless details are included / required saves so much time.

2 месяца назад
@eightsprites3778
@eightsprites3778

Write what you thinking in comments, not what’s in the code. Write a note why code does something if it’s not clear or even better refactor the code so it becomes readable. Readable code is better than complex code, don’t refactor code if it makes it harder to read or understand. Remember more time is spent reading code than writing code.

6 месяцев назад
@jk-fy8on
@jk-fy8on

I always have hard time figuring out The Prime is being sarcastic or not.

2 месяца назад
@TheSkepticSkwerl
@TheSkepticSkwerl

I have this one case that is extremely more performant by first converting the data to a hash table and then working with it and it's super wonky looking but it reduced the work time from 25 minutes to 45 seconds

6 месяцев назад
@mattmurphy7030 +1
@mattmurphy7030

I’m 40k lines into a game and so far the only real comment I’ve felt compelled to write is an outline of the pathfinding algorithm

6 месяцев назад
@wiczus6102
@wiczus6102

More often then not there are multiple ways to understand what function is doing, a comment should clarify that. For instance GetDescendantsOfType should have a comment telling you 1. whether this is recursive 2. which types are okay. 3. What is the stop condition? Is there a situation where you don't want the recursion to continue? You don't want to sift through the code just to find these things out.

6 месяцев назад
@JakobRobert00 +1
@JakobRobert00

3:40 in this scenario, I would argue that you should not name the variable "FIVE_MINUTES" because the variable name can become misleading just as the comment did. If you change 5 to a 3, you might forget to adjust the variable name.

2 месяца назад
@Jabberwockybird +1
@Jabberwockybird

Can you stop redundantly naming constants based on their expected value for FIVE MINUTES!?

Месяц назад
@uMadBrudi +2
@uMadBrudi

I think the example at 3:07 is an actual W for the JS community, because if you compare ZIG --> "if (C - 8==D)" VS JS --> "if (C - 8===D)" it actually shows that JS devs have the bigger dick operator..

6 месяцев назад
@antdok9573
@antdok9573

3:15 I'd go further and only allow math expressions in if statements whenever it's a +=1 -=1 situation. This alternatively looks like some sort of iteration, whereas X-8 == Y is a bit more mentally demanding as well as arbitrary.

6 месяцев назад
@BreathingCells
@BreathingCells

"CodeAesthetics ... is by far one of my favorite, favorite YouTubers" (1:45). Yes! With all of seven (7) videos, each one a masterpiece, we can only hope for more.

3 месяца назад
@Rockyzach88
@Rockyzach88

For me it comes natural. I just put down what I think will be useful to know there. It's like writing notes on paper. I just write stuff that I think will be useful for me in the future. That can come in different forms.

6 месяцев назад
@austin4855
@austin4855

I start with piles and piles of comments because my code usually starts out as a steaming pile. The first write is usually a single file in a single night with 4 cups of coffee, with 400 lines of code and 500 lines of comments. Then comes the first refactor, and the second refactor if it's real serious. Now I have well-structured, lightly commented self-documenting code. In the end I try to keep my comments to primarily just refs/links to outside resources like business rules the code is implementing.

5 месяцев назад
@d1ngd0 +8
@d1ngd0

Long live Tom. Tom is a genius!

6 месяцев назад
@mage3690
@mage3690

I mean, you _can_ do an optional return in C if you do "void foo(args, &returnVal);" and squint hard enough. Wouldn't recommend, generally try to stick to returns because pointers are the literal devil, but it _can_ be done.

6 месяцев назад
@TheNewton +17
@TheNewton

Comment now perfect later. Comments are context. Beginners need context and have to learn to communicate it. Technical writers need context to document. Senior devs create context and have to clarify it. Managers and stakeholders need explanations from everyone else depending on that context. The idea of not commenting is arguing for a perfect ideal code that will never exists. Just comment.

6 месяцев назад
@gamerk316
@gamerk316

Software Engineer speaking: I will ensure anyone who doesn't use/maintain clear and concise code comments will be assigned as far away from a keyboard as possible.

Месяц назад
@StdDev99 +24
@StdDev99

That only applies to those who are just calling APIs and barely have any advanced logic in their code. When you have advanced mathematics and complex algorithms and equations that are based on geometry, you'll need to explain what are you doing and why and why didn't you go for the other obvious more intuitive way. That's what comments are for. It's not to explain what's happening, it's to tell you why it's happening and what was the developer thinking.

6 месяцев назад
@NathanHedglin +1
@NathanHedglin

Exactly, well said.

6 месяцев назад
@mattmurphy7030 +1
@mattmurphy7030

Nailed it. The only real comment in my game is an outline of the pathfinding algorithm. The rest are just “this is here because ___”

6 месяцев назад
@krozareq +5
@krozareq

He states it himself he's not into math. But math is important for a lot of advanced uses. Scalars, vectors and matrices for example are prominent in a lot of areas where transformations are used. never hurts for a programmer to know how to use advanced algorithms. Who knows, he may realize he can heavily optimize something with it instead of just looping through arrays like a novice. That's fine at the small level, but with large stores of data the processing goes through the roof.

6 месяцев назад
@marshallsweatherhiking1820
@marshallsweatherhiking1820

I mostly explain the algorithm in a paragraph inside the function but at the very top of the block. Most of the comments inside the algorithm are just saying what if conditionals mean where it isn’t obvious. The most common example being at the top of an “else”. Like if I have an if block “ if ( size < max ){…” I put “max

6 месяцев назад
@BusinessWolf1 +2
@BusinessWolf1

good job, you just repeated exactly what the primogen said, including his disclaimer statement

6 месяцев назад
@lpprogrammingllc
@lpprogrammingllc

If you are implementing something complex, especially if it is something that requires you, the programmer, to remind yourself how it works via stack overflow or wikipedia, you should comment it. At the least, you should include a link to the source of the algorithm. Then, if the algorithm has multiple steps in the wikipedia pseudocode or what not, you should note where you are starting each step. There is nothing worse than having to come back to some Vector3 trig functions because of some slight change in the program requirements, and then spending several hours re-learning something you haven't needed in a year.

Месяц назад
@u9vata +2
@u9vata

If you optimize for performance you might need to describe what the code is doing and there are some other cases when you better do so. Generally I agree with the points here - yet I still heavily comment. But this is not video about "why do not comment" but more like "how to not comment"... Also useful to use comments to mark "code blocks" instead of extracting function and making you jumping around - in case that function would be not called from anywhere else and only used to structure your code. This is better style: // Find needle char *needle = strstr(...); if(*needle == '$') needle++; // Ensure start character big .... // Whateverelse ... Much better than: char* needle = LineParser.find_needle(...) LineParser.ensureStartCharacterBig(needle); this->whatEverElse(); ^^this might at first sight be "more readable" but in reality you most of the time want to know what is happening even if names are well chosen... And you cannot see the overarching logic here because it became spaghettified. Yet here you exactly DESCRIBE what you do isn't it? Like you describe in case of function names too! Of course not describe details like in the video... I also prefer to use /* */ for code blocking comments instead of // sometimes. Then you can clearly see // means "why" kind of comments or information and /* */ means "structuring". Also syntax highlight really helps you see the blocking in these cases. One more thing: You do not trust comments because they can lie... Okay... so do function names, class names, package names, any kind of names lie to you all the time too! Do not trust me? You likely did not work with stuff like "point.getX()" where it initializes X to zero if its undefined... why? Side effect like that? Lol. Also what about "lazyAsynchronousProcess(data)" that did synchronous and blocking processing??? I totally mean I met these things and many more nasty stuff. No one holds your hand not to lie like that - just do not do it! Same with comments: if you change a code and not the comment... that's on you... the above ones all came from someone entering the code and not changing names... nasty like shit. If you cannot update the comment - don't care at least delete it or something then okay. But keep stuff in synch if possible. Also to be honest I sometimes prefer seeing comments even in case it got out of synch - in a weird way it signals something nasty have happened right there - and still might help deduce the intent of the code. PS.: You do not even need AI for this "check your comment" stuff. It could be as simple as an editor marking the comment as stale and coloring it high pitch red for you if you change below it - unless you move the cursor in there... That would solve like 90% of the cases even without AI (but the AI idea is still good).. Long ago already had this coloring idea even before AI would make this easier.

6 месяцев назад
@JesseGilbride
@JesseGilbride

I'll add a comment where a line/section will need to be changed for an expected (but not current) API change, or a reminder to devs (now and future) who keep adding redundant code that this ONE THING is all that's needed, to hopefully stave off the urge to add the component or call/import yet again.

4 месяца назад
@AmirHosseinHonardust
@AmirHosseinHonardust

I usually do some kind of chapterization. Say I have a controller function which is long. I specifiy where I validate and parse the inputs, where I do bussiness logic related stuff, where I write the data into database and where I send a successfull response. I also do the day with types. Each type has a file, the file contains, type definition, type builder section, trait implementations, error type and... It helped my navigation a lot.

6 месяцев назад
@rustmoody383
@rustmoody383

Comments are great for “why”, often when I’m in position when I now that solution I posted might seems strange I want to message anyone who ever wants to edit it to double think it why it is that way. Also it is a great marker for fishy code, if something is commented - keep an eye on that one

6 месяцев назад
@ernststravoblofeld +1
@ernststravoblofeld

All these guys have a good idea, and then try to apply it to all situations everywhere. Sometimes you need a comment, so write a damn comment.

3 месяца назад
@Qewbicle
@Qewbicle

Me writing comments for my future self has saved me, sometimes just the why, sometimes some what's to make a piece less dense (sometimes I write dense code when I'm in a flow, but I won't be in that same mindset a year later). The best thing to do is to write comments to someone out of the loop just to bring them to speed. Put it where it matters, so if that specific thing changes, so does the adjacent note/comment. Those that don't give themselves/others future notes have not ran into that issue. After they have the experience of going into different projects and having to revisit the past and realize they can't put together what they thought was obvious, they have to read a bunch of code to catch up to that mindset for that moment, then they'll have wised up to what to put, where to put it, and smart enough to keep those important bits up to date.

3 месяца назад
@fulconandroadcone9488
@fulconandroadcone9488

I like the idea of commit message as a comment defining why that line was changed and when, and how it looked before and potentially linking to issue that defines a problem and how it was discovered ....

6 месяцев назад
@hearthergd7462
@hearthergd7462

I love watching these videos and pretending like I have a goddamn clue what anything is 😂

Месяц назад
@nangld
@nangld

In my personal programming language, Symta, all typenames start with a lower-case letter, while all data variables with an upper-case letter. Yeah, I'm a Prolog fan.

4 месяца назад
@xerotolerant
@xerotolerant

He’s using AI to read your comments on his video. That’s the true startup idea

6 месяцев назад
@MrSquishles
@MrSquishles

Bunus points, it makes it way harder for a language model to tell what your code is supposed to be doing if there are not comments, or comments that lie.

6 месяцев назад
@thom1218 +2
@thom1218

Programmers that can't be bothered to update a comment to reflect their change don't deserve to meddling in the code to begin with.

Месяц назад
@YeahItsThatBad
@YeahItsThatBad

I agree, don't comment what you are doing, I can see what you are doing for myself, but WHY are we doing this? If at any time some one is doing something weird or obscure in the code I force them to add a comment explaining why. A lot of times we have to do weird stuff in the codebase because a client demanded it, that should have a comment. I recently had an instance where I had to go back to code that I was involved with a few years ago. Some one asked me "why are you doing this?" So I go back to the code and I was left scratching my head, I could no longer remember. Oh, I know, let's check the commit. Well, apparently the commit had a worthless message that didn't help. Also, due some git trickery we had to do a lot of digging to find the actual commit amongst a bunch of merges. Then I tried to find why we did the code change in JIRA, oh well, I couldn't find it. The same with Slack, I couldn't find any information. If only we had added a one line comment explaining why we were doing what we were doing, or a simple comment that mentioned a JIRA ticket I would have saved myself a lot of time.

6 месяцев назад
@adriankal
@adriankal

Closing li was required just to make html compatible with XML. In html it was and is required only in specific cases.

6 месяцев назад
@DemonixTB +1
@DemonixTB

Comments need to exist to justify why something was done, so the same mistakes arent retreaded. but comments get stale, because they arent tested or statically checked. so always be careful when writing your comments to not make more assumptions then necessary.

6 месяцев назад
@muhwyndham
@muhwyndham

I prefer using test to document behavior. Hence justifying it by making the test fail if changes were made, and hopefully people read the test case name and understood the assignment

3 месяца назад
@JoelJosephReji
@JoelJosephReji

Probably not what you meant but optional first came as a part of the boost library (and later got adapted to C++ specification)

6 месяцев назад
@tubeincompetence +1
@tubeincompetence

Comments are great! Just need to find the correct level and not make obvious comments printf("Hello world"); // prints Hello world might be a bit over the top :) But yeah, I like good variable, type and function names and hopefully remove some comments. I just think they can be quite helpful sometimes. I have often found that I would have loved comments

6 месяцев назад
@JonathanSwiftUK +4
@JonathanSwiftUK

Professional programmers include comments where needed, not only to remind them how the code works when it might not be obvious, and to document blocks so as you are scrolling through you know which part you are looking at, and you can search on those comments. Thank god I don't work with Prime.. whatever his name was. And if we're measuring dick sizes I've been in IT for over 35 years :-P. But ... I always give a like for the effort it took to make, and he is funny.

6 месяцев назад
@MGMan37
@MGMan37

"to document blocks so as you are scrolling through you know which part you are looking at" The idea is if your blocks are this fucking big, they could just be functions instead named after what they do.

6 месяцев назад
@humphreykganakga7096 +1
@humphreykganakga7096

The name of the game is to reduce cognitive load. Maintainers should have enough working memory free so they can make changes without having to recall an addendum to line 3 in paragraph 4 of subsection 20 in article A of the 18th revision of document 57.

6 месяцев назад
@Thomas_Angelo
@Thomas_Angelo

I love writing comments. it's funny. it's just explaining to me in the future tf I was doing.

3 дня назад
@wewantthefunk73
@wewantthefunk73

The shop I'm in now has a practice of a large comment block at the top with a list of all changes since the beginning of the module. Reach change had an id. Then in the code the changed lines are commented out and marked with the id of the change. So there is a history of everything that's ever happened to the code. Check and mate P.S. it's COBOL and the code is 30 years old. So if you need to blame someone from 1997, it's right there. It also eliminates the need for source control. Check mate again.

6 месяцев назад
@mattmurphy7030
@mattmurphy7030

I think I need to use the restroom after reading this

6 месяцев назад
@isodoubIet
@isodoubIet

git got dunked on

6 месяцев назад
@MGMan37
@MGMan37

This sounds like a great way to have 900 comment lines for 50 lines of code

6 месяцев назад
@JapaAppa
@JapaAppa

I write lots and lots of comments explaining every single step of what a function is doing, because I am under the impression that someone who can't read code or can't read code at a high level will end up encountering my code.

Месяц назад
@HrHaakon
@HrHaakon

6:40 you talk about Optionals. They probably have always been there in some way, but the first BIG ENTERPRISE application that we all know and love is probably SOAP. Which is simple, otherwise it would be called COAP. No, but seriously, the response envelope envelops the idea correctly and robustly. Thankfully the JS developers revolted against such malificense, and figured null-values were much better.

6 месяцев назад
@ideegeniali
@ideegeniali

I wrote protocol specs documentation to talk to firmware in electronic boards i design and build. A client needed to use such boards. I sent protocol specs, he was having hard time. I sent well written, no comments, autoexplicative source code protocol parser class, and he immediately got it. He told me he apparently understands C++ way better than English and/or I can express myself more clearly in C++ than English! That's it: code IS its specs, in the most detailed description possible.

5 месяцев назад
@kahnfatman
@kahnfatman

Here to the clean code camp who say the code should document itself: This is what your function names end up look like: - setupPageSizeA - navigateToSectionFourteenParagraphThirtyTo - handleTopLeftCornerButtonClickWhenUserIsUpsetAndFrustrated ... The names are so meaningful that you don't need to write comment at all. And Shakespeare shall be proud of ya.

Месяц назад
@vitalyl1327
@vitalyl1327

We used to have Literate Programming... Now, few decades later, developers devolved to this sad state.

6 месяцев назад
@JoshuaMiller-gr6sj
@JoshuaMiller-gr6sj

I agree. Don't describe what it does but possibly why it exists.

6 месяцев назад

Далее

Premature Optimization

12:39

Premature Optimization

CodeAesthetic

Просмотров 638 тыс.

Is Stack OverFlow Evil? | Prime Reacts

38:13

Is Stack OverFlow Evil? | Prime Reacts

ThePrimeTime

Просмотров 134 тыс.

Обменялись песнями с POLI

00:20

Обменялись песнями с POLI

Gazan

Просмотров 1,6 млн

НОВОГОДНИЙ ХОРРОР

48:49

НОВОГОДНИЙ ХОРРОР

Kuplinov ► Play

Просмотров 1,2 млн

0 to LSP : Neovim RC From Scratch

30:47

0 to LSP : Neovim RC From Scratch

ThePrimeagen

Просмотров 890 тыс.

Open Source Project DESTROYED By Legal Threats

47:50

Open Source Project DESTROYED By Legal Threats

ThePrimeTime

Просмотров 112 тыс.

A small presentation of V's features at IBM

24:26

A small presentation of V's features at IBM

The V Programming Language

Просмотров 10 тыс.

Kubernetes 101 workshop - complete hands-on

3:56:03

Kubernetes 101 workshop - complete hands-on

Kubesimplify

Просмотров 1,5 млн

Software Engineering Anxiety | Prime Reacts

23:29

Software Engineering Anxiety | Prime Reacts

ThePrimeTime

Просмотров 124 тыс.

How principled coders outperform the competition

11:11

How principled coders outperform the competition

Coderized

Просмотров 1,2 млн

Why Would Anyone Hate TDD? | Prime Reacts

46:52

Why Would Anyone Hate TDD? | Prime Reacts

ThePrimeTime

Просмотров 95 тыс.

Dependency Injection | Prime Reacts

28:34

Dependency Injection | Prime Reacts

ThePrimeTime

Просмотров 173 тыс.

Git Flow is Bad | Prime Reacts

34:31

Git Flow is Bad | Prime Reacts

ThePrimeTime

Просмотров 196 тыс.

S22 Ultra зеленый путь!

0:59

S22 Ultra зеленый путь!

Sergey Delaisy

Просмотров 205 тыс.

iMac или ПК - что лучше?

0:59

iMac или ПК - что лучше?

CompShop Shorts

Просмотров 664 тыс.

This CPU is FREE!

18:09

This CPU is FREE!

Linus Tech Tips

Просмотров 644 тыс.

Худший телефон!

0:25

Худший телефон!

𝙂𝙀𝙉𝙀𝙎𝙄𝙎

Просмотров 33 тыс.