2013年9月10日 星期二

Psychology of programming - How to place the left brace

After read Allman Style, K&R style, GNU style
https://en.wikipedia.org/wiki/Indentation_style

ISO C99, ISO C++ 2011, ISO C++ 2014, ISO C++ 2020
https://www.mediafire.com/file/3xy4u72o4g9uft2/ISO_C_and_C%252B%252B__International_Standard.zip

Hungarian notation & its history
https://idleloop.com/hungarian/
https://en.wikipedia.org/wiki/Talk%3AHungarian_notation
https://learn.microsoft.com/en-us/dotnet/standard/design-guidelines/general-naming-conventions

The Psychology of Computer Programming & An Introduction to General Systems Thinking by Weinberg
https://en.wikipedia.org/wiki/Gerald_Weinberg

Also wrote in many system:
Linux kernel, Zephyr, C#, Inline assembly, Android framework & App, IOS Object-C App, Python3 for AI, Scala for Risc-V, Buildroot, Bash, Makefile and trace GNU gcc source. Then post this topic.

We are programming with gcc g++ arm-linux-gcc aarcg64-linux-gcc gdb gdbserver that are all released by GNU

The left brace used in GNU is similar to Allman style, that is placed on the next line of the conditional expression.

The Linux kernel uses the K&R style, that is placed on the end of the conditional expression.

Some people say it's better on the next line, some people say it's better at the end of the line.
In python3 there is no brace problem at all.

The less programmatic semantics are combined or simplified in the brain, the easier to read.
So, engineers have more time to focus on security, speed, cpu loading.

Many ruler who set the company's syntax rules they forget...
1. The ruler, are you trying to use someone else's new syntax?
2. The ruler, Have you introspected the number of combinations or simplifications of semantics in your brain?

For examples:
1.
if you are going to america
         Then you should get a passport first
         Check available hotels in California

Otherwise if you are going to Japan
         learn basic greetings
         Check available hotels in Tokyo

2.  
if you are going to america

         Then you should get a passport first
         Check available hotels in California

Otherwise if you are going to Japan

         learn basic greetings
         Check available hotels in Tokyo  

3.
if you are going to america
         Then you should get a passport first
         Check available hotels in California

    Otherwise if you are going to Japan
         learn basic greetings
         Check available hotels in Tokyo

4.
if you are going to america
         Then you should get a passport first
         Check available hotels in California
    Otherwise if you are going to Japan
         learn basic greetings
         Check available hotels in Tokyo

For example 1, we understand quite well but in the middle of example 3、4, we need combine more thinking in uncertain. Now you should know how to put left brace. Here is an open answer.

1. Try to understand new syntax of other's syntax
2. Introspected the number of combinations or simplifications of semantics in your brain
3. Pay more attention to system security, speed and loading

Don't waste time polishing the frame of the painting, but the painting itself.
If so you will be a good syntax ruler!!!

1 則留言:

  1. Translate in Chinese, I buy the e-boos, so please buy them to support the author.
    1.
    https://www.mediafire.com/file/xcnu3hys9tbskn1/An_Introduction_to_General_Systems_Thinking.pdf
    2.
    https://www.mediafire.com/file/trx2ro46brvcw4c/The_Psychology_of_Computer_Programming.pdf

    回覆刪除