3 ms·
The biggest challenge is writing readable code and this should be focused on a bit more on top of does the code work and pass the tests for the programming assi
by bern4444 4y ago
The biggest challenge is writing readable code and this should be focused on a bit more on top of does the code work and pass the tests for the programming assignment.
Everyone has their own style of writing code but I find code in the vein of
bool system_has_room_to_store_new_data = num_objects < db.limit;
if (system_has_room_to_store_new_data) {
// ... proceed
}
is so much easier vs
if (num_objects < db.limit) {
// ... proceed
}
There is a lot like this that would dramatically improve every engineer's ability to write readable code. The biggest difference between academic code and business code is the number of people contributing. Please let's focus more on writing human readable code and less on being as terse as possible.
In almost every language, the compiler can and will inline this for you avoiding the extra variable and memory usage and even if it won't in a GC language the memory will be freed nearly immediately.
This doesn't need to be a course, but it should be applied across existing courses, sample code shown in class etc.
Also, no more
for (int i = 0; i < myArry.length; i++ {
myArr[i] += 1
}
I have almost never seen this in any codebase I have worked with. Teach .map, .filter, .forEach, etc. Every language has these methods.
Another one is early returns for validation checks:
if (someConditionIsntMet) {
return null;
}
if (someOtherConditionIsntMet) {
return null;
}
// Proceed with logic and function implementation
This avoids a lot of needless indenting. Putting the checks at the top is so easy. You can even throw all the predicates in an array, loop and return true if all are true or false if one or more is false.
FP has also become far more popular now - a brief overview of Option, Result/Either, and Future types would be nice. We don't have to get into the theory of functors or monoids or monads, but students should be aware there are better patterns of handling errors than try/catch and throw