Re:Ask HN: What are some examples of good code?
by chillingeffect on Monday March 13, 2017 @02:42PM
(#13860969)
Right off the bat, I see multiple instances of str* functions where strn* functions should be used. I'm also wondering about this variable "server" which seems to have an unknown definition. There are lots of gotos, and many other deferred high-quality conventions, such as explicit parenthesis in comparisons, re-ordered fields in comparisons, chains of else ifs, where a switch would be preferable.
I also see lots of prototypes (all?!) defined at the top of the file instead of in a header file. They could be made static.
Also, the generic type "int" isn't a good idea because it can change, it helps avoid porting problems to specify the size (int32_t, uint64_t, etc.)
And the memcpy()'s should be changed to memcpy_s().
On the bright side, the comments are quite good and plentiful. Refreshing!
I also see lots of prototypes (all?!) defined at the top of the file instead of in a header file. They could be made static.
Also, the generic type "int" isn't a good idea because it can change, it helps avoid porting problems to specify the size (int32_t, uint64_t, etc.)
And the memcpy()'s should be changed to memcpy_s().
On the bright side, the comments are quite good and plentiful. Refreshing!