10
hardfault
26d

I am writing a UI api for microcontrollers as a pet project.
I usually follow kernel.org for coding style so visited the site to see if there are any changes, these docs are so funny

Comments
  • 4
    I am pretty sure that Linus is dead serious about that style guide. Names matter.
  • 4
    @Oktokolo yeah my favorite ones is this ( don’t use cute names )
  • 1
    @hardfault
    I never call anything tmp.
    Counters are trditionally called "i", "ii", or "iii" (but if there are three nested for loops you probably need to refactor that shit).
    Temporary collections are most often "parts".
    Temporary natural numbers are "n" or "m".
    Coordinates are "x", "y", or "z".

    But naming something "tmp" is a sure sign that you actually don't know, what it is (not only speaking of the data type).
  • 1
    @Oktokolo I think it's perfectly fine to use tmp for certain things like a function that performs some trivial manipulation of a data structure and needs to store something temporarily
  • 3
    @Oktokolo tmp is perfectly fine if it's use is obvious. That means your function is so small that you can obviously see what it is.
  • 5
    tmp is fine if it's obvious in the context. I would fire you the moment you start using tmp2 and higher in the same scope.
  • 0
    As a rule of thumb, for all inobvious/meaningless names (like tmp) I should be able to position the viewport such that all uses of the variable are included and every other visible name makes sense.
  • 0
    @electrineer
    Yes, it would be tolerable in the really obvious cases. But i never had giving a proper name leading to code becoming less obvious. And if you understand what the code does (wich an obvious cases implies), better names come into mind automatically.
    So i still would advice against using "tmp".
Add Comment