Send Close Add comments: (status displays here)
Got it!  This site "robinsnyder.com" uses cookies. You consent to this by clicking on "Got it!" or by continuing to use this website.  Note: This appears on each machine/browser from which this site is accessed.
CS: Code tricks
by RS  admin@robinsnyder.com : 1024 x 640


1. CS: Code tricks
TrickOne should not use coding "tricks" unless necessary. Sometimes such "tricks" are necessary.

When necessary, such "tricks" should be documented/commented appropriately. Bad comments explain the code or overly explain the algorithm used, etc.

In general, KISS = Keep It Simple Stupid. This is line with Occam's razor, also known as the "law of parsimony".

2. KISS
KISS (no, not the rock band by that name) is a design principle thought to originated in the U.S. Navy about 1960. Unnecessary complexity in software systems is a major source of design and implementation errors.

3. Occam's razor
Occam's razor is a principle that the simplest explanation is often the best explanation. It is also known as the "principle of parsimony" or "law of parsimony". In problem-solving, it states that "entities should not be multiplied beyond necessity".

Information sign More: William of Ockham

4. Rube Goldberg
Reuben Goldberg (1883-1970), or Rube Goldberg, is best known for his machines that show what can happen when the KISS principle is not used.

5. Self-operating napkin
A famous Rube Goldberg cartoon is of Professor Butts from 1931 and shows a self-operating napkin.

6. Reliability
The price of reliability is the pursuit of the utmost simplicity. It is a price which the very rich may find hard to pay. Tony Hoare (British computer scientist)

Information sign More: Tony Hoare

7. Tricks
The competent programmer is fully aware of the strictly limited size of his own skull; therefore he approaches the programming task in full humility, and among other things he avoids clever tricks like the plague. Edsger Dijkstra (computer scientist)

Any tricks used require one to remember that trick in the brain. Each such trick takes more effort to remember.

Information sign More: Edsger Dijkstra

8. Briefness
It takes time to make things more concise - whether it be computer programs or letters - and still convey the desired meanings.

Blaise Pascal (French mathematician, physicist, inventor, philosopher and theologian) was the inventor of the calculator and other inventions, wrote the following (in French), from Wikipedia.

French: Je n'ai fait celle-ci plus longue que parce que je n'ai pas eu le loisir de la faire plus courte.

Literal translation: I made this one [letter] longer only because I have not had the leisure to make it shorter.

This could be translated as follows. I would have written a shorter letter but I did not have time.

Information sign More: Blaise Pascal

9. Solutions
Are you quite sure that all those bells and whistles, all those wonderful facilities of your so called powerful programming languages, belong to the solution set rather than the problem set? Edsger Dijkstra (computer scientist)

Information sign More: Edsger Dijkstra

10. Android example
Every operating system has issues where it does not work the way it is supposed to work or the way one would want it to work.

This is true of the Android Java-based development system.

11. Caching
Caching in order to improve performance often causes many subtle correctness issues.

Web browser caches create many correctness issues with using some web sites. And cookie caches create additional issues as there may be no easy way to remove a cookie once created. The Android Java-based development system tries to cache the list items in a list box. When one tries to do custom things, there are issues.

About 2018 I was trying to do some custom text formatting and sizing of list box items. I kept having issues where it would work, then not work, etc. I tracked down the problem to a "feature" of how the Android Javas-based development system worked for list boxes and list items. One had to use a "trick". But that "trick" had issues, so one had to use another "trick". This led to a third "trick", each of which did not work all of the time. The deciding factor was when I needed to support many different languages and, in particular, right to left languages. Each of these introduced more issues.

And I needed a "touch" to be located on the line as to what word was "touched". No luck.

I ended up using single custom list times and did the complex text formatting to use these individual list times. It worked well, avoided tricks, but added some complexity to the application.

12. End of page

by RS  admin@robinsnyder.com : 1024 x 640