DEV Community

Discussion on: Code Smell 24 - Boolean Coercions

Collapse
 
mcsee profile image
Maxi Contieri

what is 'i' ?

what real world entity does it represent ? the letter 'i' ? Why would you compare a letter with a number ?

Thread Thread
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️

Considering the example talks about C, i is probably a counter variable for a numeric loop.

Thread Thread
 
mcsee profile image
Maxi Contieri

i think we should name it 'counter' or 'index'
We are doing software, not math

Thread Thread
 
yoursunny profile image
Junxiao Shi

My real code uses the variable name res.
github.com/usnistgov/ndn-dpdk/blob...

int res = rte_hash_add_key_with_hash_data(pcct->tokenHt, &token, hash, entry);
if (likely(res == 0)) {
  break;
}
Enter fullscreen mode Exit fullscreen mode

That likely is not "premature optimization". This code is for a high speed router that processes millions of packets per second.

Thread Thread
 
mcsee profile image
Maxi Contieri

I don't know what 'res' stands for.

But if you performed a real benchmark on the code and found out it really needed to be optimized it does not classify as 'premature'.
I'm ok with that since in this very special case speed is more important than readability

Thread Thread
 
yoursunny profile image
Junxiao Shi

res means result. It is common in C code.

Thread Thread
 
mcsee profile image
Maxi Contieri • Edited

ok. that's why i don't like low level languages. They are more cryptic.
I try to specialize on higher level languages. Most code smells apply to them.

I suggest not to use 'res' 'i' ir 'result' as variable names since they have no business meaning.

more examples here:

maximilianocontieri.com/what-exact...

Thread Thread
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️

certain things like res and i are so common that I'd consider them expressive variable names, but there's not many. For res, I really like the pascal feature of assigning to the subroutines name, because presumably that's already a descriptive name for the result value.

re not liking low level languages, it seems to me like high- and low-level languages have completely different appeals (I happen to like both of them), so one might like one but not the other. Thinking in systems and poking at bits are as much different areas as back-end and front-end.

Thread Thread
 
mcsee profile image
Maxi Contieri

you are absolutely right. They are different tools for different purposes