4 ms·
Look at the common theme among your suggestions: - do not use builtin operators in C for that, - instead create new functions, e.g. addMeters() - hide t
by jasode 10y ago
Look at the common theme among your suggestions:
- do not use builtin operators in C for that,
- instead create new functions, e.g. addMeters()
- hide the int in *.c file
Those are "best practices" instead of compiler-enforced type-check errors. Likewise, suggesting a best practice such as "don't free() memory twice" is not the same as a GC-language (Lisp/Java/C#/Go) freeing memory on the programmer's behalf or a static-ownership checker (Rust) preventing a programmer from making that mistake.
- mikulas_florek 10y agoYou can write the exact same wrong code in e.g. C# public class Meters { public int x; } public class Yards { public int x; } public class Kilograms { public int x; } Meters m = ... Yards y = ... Kilograms k = ... k.x = m.x + y.x; all my sugestions for C are basically the same in C# - do not use builtin operators in C# for that instead create new functions, e.g. addMeters() - hide the int in *.c file == make it private in c#
- kazinator 10y agoDon't free memory two or more times is "OMG don't flippin' do that", not a "best practice". ;) "Best practice" is a choice from among justifiable alternatives.