Winning a debate on dialectics is not wining, is obfuscating to the point of exhaustion.
See the code as a conversation with a computer. Keep asking questions.
Don’t fear to make a complex structure if it will lessen the load for the working parts.
This means that a good compiler will take a huge load easily, as it can take it’s time to build the program.
Once the program is built, any sacrifice you made to have more simple code will translate into less efficient programs.
If you have to choose, always sacrifice compiling instead of clarity.
You don't control running time. That's up to the processor optimization, and maybe the universe.
If you have to choose, always sacrifice the apparent "time’s efficiency" instead of clarity.
When in doubt, back to basic.
Computers only know Data and Processes.
Data abstracts knowledge.
Processes undertake actions.
Functions are processes that produce Data.
Everything else is based in this fundamental principles.
All great artists from the Renaissance sketched their pictures first. They had access to all kinds of fabrics and tints, but they would always start with charcoal and paper.
You don’t need a fancier setup, but a simple one that makes what you need.
Standard means transportable into more systems. It will also be easier to maintain and improve in the future.
To paraphrase Kant:
Write by functionality, not by algorithm. State the algorithm in notes under the definition if that’s relevant.
Ideally, a program would be completely statically (compile-time) type safe.
You don’t need to handle errors caught at compile time. And makes for a clearer code.
What cannot be checked at compile time should be checked at run time.
A leak is colloquially “anything that isn’t cleaned up.” The more important classification is “anything that can no longer be cleaned up.”
Relying on system with guaranteed cleanup such as file closing and memory de-allocation upon process shutdown can simplify code. However, relying on abstractions that implicitly clean up can be as simple, and often safer.
Time and space that you spend well to achieve a goal (e.g., speed of development, resource safety, or simplification of testing) is not wasted.
To make good things, build good parts. And connect them well.
Divide and conquer. Your enemy is the code. Divide him.
Use libraries.
Better yet, use clear, well documented, and well designed libraries.
Write so your code can help others stand on your shoulders.
Not all Exceptions are Errors.
“Performance” is not affected by handling Exceptions. Stop using it as an excuse.
Just give one responsibility to each function. Then, build on top.
“The Single Responsibility Principle (SRP) is a computer programming principle that states that every module or class should have responsibility over a single part of the functionality provided by the software, and that responsibility should be entirely encapsulated by the class. All its services should be narrowly aligned with that responsibility.”
“The SRP states that a class or module should have one, and only one, reason to change.”
Classes and functions should be small and obey the Single Responsibility Principle.
Functions should have no side effects
Specify explicitly in the function contracts.
Encapsulate rule violators. Keep them local. Avoid its leak.
Sometimes, ugly, unsafe, or error-prone techniques are necessary for logical or performance reasons. This doesn’t mean you can’t control them.
What : At the library, program, or function level. Functionality.
How: Inside the library, program, or function.
Why: When called.
It would be even better if your code was self explanatory.
Imperative is the How.
List of steps
Declarative is the What.
What we have and what we need.
Don’t let them evolve into Features.
Warn all those who may enter a laborious hellish task of what horrors await them.
I find this comment just perfect:
/**
Dear maintainer:
Once you are done trying to 'optimize' this routine,
and have realized what a terrible mistake that was,
please increment the following counter as a warning
to the next guy:
total_hours_wasted_here = 42
**/
<2 WTFs/minute ⇒ Good Code
>5 WTFs/minute ⇒ Bad Code
>10 WTFs/minute ⇒ Restart
>20 WTFs/minute ⇒ Fire that guy
dude, WTF ⇒ +3
WTF is this sh!t ⇒ *2
What are people around you optimizing for?
Understand what is the customer needs.
If you have to do it more than twice, a computer should do it for you.
This is known as the Linus’ Law.
Double check what you read out there.