Using Numbers in Your Code is BAD?!? (low level code review)

Поделиться
HTML-код
  • Опубликовано: 10 авг 2023
  • One of my viewers submitted some code that they wanted me to review. Code reviews are EXTREMELY important in programming. You should always be giving them, and getting them, to improve your skills as a programmer.
    In this video, I grade the viewers submission on the codes functionality, ease of understanding, if the code is maintainable, and if someone could expand on it.
    GO GIVE THEM A STAR ON GITHUB RIGHT NOW: github.com/KanzenTaiwa/rcg
    EMAIL ME YOUR CODE: lowlevellearning(at)gmail(dot).com
    🏫 COURSES 🏫
    Learn to code in C at lowlevel.academy
    🙌 SUPPORT THE CHANNEL 🙌 Become a Low Level Associate and support the channel at / lowlevellearning
    🔥🔥🔥 SOCIALS 🔥🔥🔥
    Low Level Merch!: lowlevel.store/
    Follow me on Twitter: / lowleveltweets
    Follow me on Twitch: / lowlevellearning
    Join me on Discord!: / discord

Комментарии • 296

  • @JoelJosephReji

    I always though that the code comments should go in the .h file because that is the file which sort of gives the functions which are available to be used.

  • @OskarP2601

    chat is this real?

  • @bebre_2288

    Why so many comments in function declaration in STATICALLY TYPED language? This is basically useless because everything you need is stored in first line: function DECLARATION

  • @adrianbunea2006

    I don't believe you're actually recommending comments. Seeing comments is a code smell, it means you failed to write understandable code.

  • @Eysvar
    @Eysvar  +181

    My biggest issue looking at this code is how things are named. You touched a little on this with function names, but using Array as the name of the struct being passed around is objectively a bad idea. Container is about the same level of abstract (but much less confusing), however using a name like RandStrContainer would have probably been the best option here because of how descriptive it is. Plus, good names reduce the need for comments (doc comments are always good though).

  • @williamdrum9899

    Personally I think certain numbers are fine like 0, 1, and powers of 2, or (power of 2) minus 1. How you display them is very important. I always do memory addresses in hex and bitmasks in binary

  • @unknownceres5714

    No, all x86 code is binary. You have to use numbers.

  • @protonmaster76

    Instead of having all the allowable character types in one array and then using magic number indexes into the array for the different types, have 4 arrays of the character types. Then build an array of the types the user wants and make the random selections from there. It makes the function with the large case statement in it redundant, the user can select types in any order, all the magic numbers disappear and its way easier to maintain.

  • @vast634

    This trivial program did not even do what it was supposed to (repeat generation). Thats a fail.

  • @H3liosphan

    Yeah the srand bit won't work well if it's in a microcontroller or embedded processor - chances are the whole chip will bootstrap in the same way most times and the millisecond count will be close if not the same, THEN you'd use something different. Only introducing a fair bit of asynchronous-ness to the code, RTOSes, eg blocking on unpredictable IO devices, things like that. The fact as a user on a PC you can choose to launch the program when you want, is where tv_nsec as a random seed works fine.

  • @AllanSavolainen

    Oh an no, you should not duplicate code in the comments, so don't do:

  • @catlooks
    @catlooks  +78

    I think a huge problem with maintainability here is the double interval input for generating character list. It works with 4 choices, but the moment there are more than 4, 2 intervals won't cut it (for example "135" will require 3 intervals). Then the array intervals are the main point of confusion, so they probably need to be constants. So the solution is to:

  • @obvMellow

    its funny that i dont know almost anything about C and i only code for fun but i still enjoy watching your videos. keep up the good work!!

  • @user-dc9jl2ob8z

    Love the video! Lots of people only encounter their first code review on the job, so it's super helpful to see how people read and use code in more of these videos :)

  • @KramerEspinoza

    Nice review, mostly agree. Only the suggestion to add comments like : returns void falls to me in the category a = 1 // set a to one

  • @ViniciusNegrao_

    IMHO, magic numbers are fine as long as they're immediately understandable. For example: writing (24 * 60 *60) instead of (86400)

  • @hexadecimalpickle

    Function names should be verbs. `arraySize()` is not a good name. `resizeArray()` is better as it explains the action taken and allows you to use nouns such as `arraySize` for variables.

  • @hkp9257
    @hkp9257  +13

    I would love to see some regular code review videos.

  • @DmoneySauce

    Your channel is so awesome! It's crazy how much I learn in every video!