In C/C++/Java/JavaScript, an if
/for
/while
statement may be used with
exactly one regular statement in its block, no more, no less. If you want the
block to have no statements, you must use a ;
to indicate an empty statement.
If you want more than one statement, you must use {}
to create a compound
statement. This results in great controversy regarding the use of braces.
Continue reading
I’ve recently discovered a new trend in object-oriented programming. These days,
some people are saying that when writing a class, we should always prefer to use
composition over inheritance. This means that whenever we feel tempted to
inherit from another class, we should instead make that class an instance
variable of our new class and write wrapper methods for the methods that we need
to import into our new class. If you need polymorphic behavior, use interfaces
to fit your static types into polymorphic variables.
Continue reading