lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Forrest Christian (List Account) <lists@packetflux.com> wrote:

> I figured I'd add my $0.02:

Thank you for your feedback! I have done some reading about code smells[1]
and I get the impression that using such typedefs may come down to a style
choice versus a serious problem in and of itself.

I do my utmost to try to keep my code clean, obviously I am not perfect but
I really do try to learn from my mistakes, and the mistakes of others, and I
try to not be obstinate for no good reason.

Not using typedefs to create simple type aliases is in style guides[2], but
I really didn't find much evidence of it being a code smell. The verbose and
informative WikiWikiWeb[3] site does have a rule[4] I have heard of before
which is similar: The more a variable is used the shorter it should be.

On the main Code Smell page of WikiWikiWeb they make some observations about
how the approach to code smells can be pragmatic or purist. Which means that
depending on your view a code smell either hints at possible bad practice
for a pragmatist or is a sure sign of bad practice to a purist.

They also have this phrase on that same page which I found amusing:
"Rules are for the guidance of the wise and the obedience of fools."

The idea of saving space was not in terms of physical space on media, but
rather that of source code line length. Also, typing "ccstr" is just faster
than typing "const char *" all the time as well... coders are often lazy! ;)

That laziness is probably why typedefs exist for the various unsigned data
types as well... 'uint' is much nicer to type instead of 'unsigned int'.

I have a bunch of source code from various external projects sitting around
on my drive so I did a quick grep of it all to see if I could find some
examples of the 'const char *' typedef... LLVM, clang, emscripten, a number
of Apple source files, and a bunch of Windows source files all hit.

Some of the examples of things people think are code smells that I can't
really agree with were using typedefs to mask 'struct' from types. Another
person advocates not using the macro preprocessor because it hides the
code behind a macro, so you should really use functions instead.

There were more examples, but it is getting late as I've really got to get
some sleep... I've been reading about code smells now for far longer than
I anticipated. I didn't expect this subject to be quite as controversial
as it appears to be... but then I guess that also doesn't surprise me! ;)

~Paige

[1] Did a Google search for "code smell examples" and read a good number
   of the sites that were more than just a list of terms.

[2] https://www.kernel.org/doc/html/v4.10/process/coding-style.html

[2] http://wiki.c2.com/?CodeSmell

[3] http://wiki.c2.com/?VariableNameSameAsType under Criticisms