Qualities of good code - OOP edition
ok, so what is ~~~software~~~ engineering?
engineering is the application of scientific, economic, social, and practical knowledge in order to invent, design, build, maintain, and improve structures, machines, devices, systems, materials and processes
software engineering is the study and application of engineering to the design, development, and maintenance of software
Even private code has an API
- 75% reading (understanding code) https://blog.codinghorror.com/when-understanding-means-rewriting/
- easier maintenance
- it's cool
- naming
- increase/decrease
- add/delete
- insert/remove
- prev vs previous
- in names, parameters etc.
- use of standard patterns
- error handling
e.g.
throw Error
vsconsole.error()
- ... consistent code style in general
Examples
- git
git fetch
+git merge
=git pull
vsgit checkout
+git branch
=git checkout -b
git commit
ignores local, unstaged changes in foo.txt;git commit foo.txt
doesn’tarray_key_exists('b', $b)
vsproperty_exists($c, 'd')
- functions have no side effects
Examples
- sides of rectangle vs square
- it should be easy to understand code by exploring it
- encapsulation - logical hinding
- inheritance couples code more than composition
- favor object composition over class inheritance
- make you code do all that is needed, but nothing more
- you may never need extra generality
- when it comes you may have more knowledge how about the use of your code
- it's easier to add code to simple API vs complex one
- state bugs
- GoF
- why design patterns?
- of course :-D
- yup!