Go doesn't allow conversions from and to boolean type altogether.
Meanwhile in C, it's normal to test an integer as boolean, but I'd rather write if (i == 0) although I know the compile will optimize the comparison away.
Learn something new every day.
- I am a senior software engineer working in industry, teaching and writing on software design, SOLID principles, DDD and TDD.
Location
Buenos Aires
Education
Computer Science Degree at Universidad de Buenos Aires
Exactly ! Let the compiler do it for you if it is safe.
Go is much stricter than C. I think Go lacks several important features like Exceptions or Full Closures. Once it catches up with older languages it would be an excellent option
Learn something new every day.
- I am a senior software engineer working in industry, teaching and writing on software design, SOLID principles, DDD and TDD.
Location
Buenos Aires
Education
Computer Science Degree at Universidad de Buenos Aires
Learn something new every day.
- I am a senior software engineer working in industry, teaching and writing on software design, SOLID principles, DDD and TDD.
Location
Buenos Aires
Education
Computer Science Degree at Universidad de Buenos Aires
Learn something new every day.
- I am a senior software engineer working in industry, teaching and writing on software design, SOLID principles, DDD and TDD.
Location
Buenos Aires
Education
Computer Science Degree at Universidad de Buenos Aires
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
Learn something new every day.
- I am a senior software engineer working in industry, teaching and writing on software design, SOLID principles, DDD and TDD.
Location
Buenos Aires
Education
Computer Science Degree at Universidad de Buenos Aires
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.
Learn something new every day.
- I am a senior software engineer working in industry, teaching and writing on software design, SOLID principles, DDD and TDD.
Location
Buenos Aires
Education
Computer Science Degree at Universidad de Buenos Aires
Learn something new every day.
- I am a senior software engineer working in industry, teaching and writing on software design, SOLID principles, DDD and TDD.
Location
Buenos Aires
Education
Computer Science Degree at Universidad de Buenos Aires
Go doesn't allow conversions from and to boolean type altogether.
Meanwhile in C, it's normal to test an integer as boolean, but I'd rather write
if (i == 0)
although I know the compile will optimize the comparison away.Exactly ! Let the compiler do it for you if it is safe.
Go is much stricter than C. I think Go lacks several important features like Exceptions or Full Closures. Once it catches up with older languages it would be an excellent option
Shouldn't that be
if (i != 0)
...?what is 'i' ?
what real world entity does it represent ? the letter 'i' ? Why would you compare a letter with a number ?
Considering the example talks about C,
i
is probably a counter variable for a numeric loop.i think we should name it 'counter' or 'index'
We are doing software, not math
My real code uses the variable name
res
.github.com/usnistgov/ndn-dpdk/blob...
That
likely
is not "premature optimization". This code is for a high speed router that processes millions of packets per second.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
res
means result. It is common in C code.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...
certain things like
res
andi
are so common that I'd consider them expressive variable names, but there's not many. Forres
, 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.
you are absolutely right. They are different tools for different purposes
Depending on whether you want true or false. I usually test for error condition and return early.
Good fot both languages
I prefer GoLang aproach.
Booleans are Booleans