In the eyes of native programmers, you may write fake code ......, Code in the eyes of programmers...

Source: Internet
Author: User

In the eyes of native programmers, you may write fake code ......, Code in the eyes of programmers...

The programmer has a classic joke: The XX language is the best language in the world. Then you can argue that tomorrow morning. The programmer really assigns something else. How can this problem be solved? The first programming language you are familiar with is your native programming language. The influence of this native language will be deep-rooted and subtle. Even if I have learned other languages later, for example, C ++ programmers can be converted into C # programmers or JAVA programmers, an interesting phenomenon is, in the eyes of programmers whose native language is C #, they can view the code of the conversion programmer. Even if it looks like it can be compiled, the syntax is correct, and the code can be run. However, the differences can be clearly seen from the code layer.

Everyone has a mother tongue. For example, if you read this article, I guess the possibility is that your mother tongue is Chinese and OK, then you will easily understand what I am talking about below. When a person is a baby, the language he learns is his/her inherent ability. He can listen at the age of 1 and talk at the age of 3. Then, even if he is 30 or 50 years old, when we learn, think, and talk to ourselves in silence, our language will be our mother tongue. Even if you have spent a long time learning a foreign language, the most common examples in China are English or Japanese. Every day you practice and communicate, it is hard to change the influence of your mother tongue on us.

For example, the standard expression in English is haven'tseen you for a while or It's been a long time sine we met last time. According to chinenglish in Chinese, it becomes Long time no see. Now that China is strong, foreigners are beginning to accept this statement, and even foreigners in the American TV series will say this,

In the field of programming, I think this phenomenon also exists. Today, I will take C # as an example to illustrate the "fake code" written by pseudo C # programmers "......

Example 1: Escape string writing

 

 1     String str1 = @"C:\Windows"; 2     String str2 = "C:\\Windows"; 3     String str3 = @"This is my little brother, George. 4 This is Mummy Pig. 5 And this is Daddy Pig. 6 Peppa pig. 7 Muddy Puddles. 8 It is raining today. 9 So, Peppa and George cannot play outside.10 Daddy, it's stopped raining.11 Can we go out to play?12 Al right, run along you two.13 Peppa loves jumping in muddy puddles.14 I love muddy puddles.15 Peppa. If you jump in muddy puddles, you must wear your boots.16 Sorry, Mummy.";17     String str4 ="This is my little brother, George."+18 "This is Mummy Pig."+19 "And this is Daddy Pig."+20 "Peppa pig."+21 "Muddy Puddles."+22 "It is raining today."+23 "So, Peppa and George cannot play outside."+24 "Daddy, it's stopped raining."+25 "Can we go out to play?"+26 "Al right, run along you two."+27 "Peppa loves jumping in muddy puddles."+28 "I love muddy puddles."+29 "Peppa. If you jump in muddy puddles, you must wear your boots."+30 "Sorry, Mummy.";

 

Str1 is recommended in C #, because it is closer to daily use. You do not need to add any escape characters. Str2 is closer to C ++ or Java, and can be used directly by Copy. After reading str3 and str4, C # Have @ syntax, in addition to solving the transfer character problem, it also solves the problem of line feed writing. Str4 is a common method in Java. It can also be written in C #, but it will expose your pseudo C # programmer's identity.

Example 2: Nullable

  In this example, each language has its own special syntax. A language is different from other languages because it is different from other languages. Generally, some general syntaxes will be retained for promotion purposes, but some advanced syntaxes will be recommended for you. It is easy to distinguish between true and false C # programmers.

For example, the following example shows that nullable is a unique design in C #. It solves the possible null condition for data to be read from the database, that is, there are two types of data, has a value or null. In actual processing, we often need to perform special processing on null values and assign values. In order to simplify the operations of the Three-object operator, is there ?? This operator.

// General syntax of the Three-object operation: Applicable to Java, C ++, and other num3 = num1 = null? Num1: 5.34; // C # special writing num3 = num1 ?? 5.34;

 

Example 3: Circular writing

  Loop is the basic syntax control structure in various languages. From this structure, we can also see the preferences of various language designers, of course, from the programmer's code, we can see which kind of his mother tongue is, or even the programmer's learning to write code.

// JS Writing Method: for (I in n) {n [I] = 0;} // Java or C ++ Writing Method for (int I = 0; I <10; I ++) {if (n [I] = null) n [I] = 0;} // C # statement: foreach (var item in n) {if (item) item = 0 ;}
// JS ES6 statement:
For (p of n) {p = 0; // The JS Code above is different: p is equivalent to n [I]}.

 

First, let's talk about JS writing. Loop variables do not need to set the type. In fact, there are not many for loops in JS. The more common way is Lamdba writing.

C ++ is the original method, which can be used in other languages for general Copy code.

C # The foreach writing method is introduced, which is introduced by other languages later. JS contains List. forEach (p) =>{ return p> 5 ;}) and other release versions.

Example 4: Model Definition Statement

// Model class definition of C #: standard public class Test {public string name {get; set ;}; public int age {get; set ;}} // The Model of C ++ defines public class Test {public string name; public int age;} // The Model of JAVA defines public class Test {public string name; public int age; string getName () {return this. name;} void setName (string name) {this. name = name;} int getAge () {return this. age;} void setAge (int age) {this. age = age ;}}

 

In C #, if you use Java or C ++, you can also use it. However, using C #'s proprietary writing method can obviously get twice the result with half the effort.

JAVA syntax also supports writing class definitions like C ++. However, in actual use, once get or set operations are involved, write methods are required one by one, although many ides can help with automatic addition, it is a bit lengthy from the perspective of code. Some component plug-ins do not need to write get or set methods, but they are not basic support.

Example 4: create a new class

// Public class Platypus {String name; Platypus (String input) {name = input;} Platypus () {this ("John/Mary Doe ");} public static void main (String args []) {Platypus p1 = new Platypus ("digger"); System. out. println (p1.name) ;}// C # Write public class Platypus {String name {get; set ;};} public static void main (String args []) {Platypus p1 = new Platypus {name: "digger "};}

The above clearly shows that the constructor in C # can be used to directly assign values to member variables to generate instances, greatly reducing the amount of code (if this class is used only once or twice ). In fact, this writing method is more common in JS syntax, which is rarely used by many junior C # programmers.

OK. In fact, if we continue to give examples, we can also have many examples. Here I don't want to say how advanced C # is. It seems that the syntax is much more concise than other languages. Many years of programming practices tell me this is not the case. In the background Server programming field, JAVA and C # are the mainstream. They are still absorbing various advanced syntaxes to improve themselves. Both front-end JS and back-end Node development use the unified js syntax, while the js syntax is just like a year, and three years is a big Gap. From a longer dimension, all languages are also developing in real time. For example, JAVA began to introduce Lamdba writing, JS standards were evolving year by year, and New syntaxes such as promise were incorporated. A long-term trend is that a variety of excellent writing syntaxes will be introduced from one language to another, and each language will eventually become more and more similar. It is far less difficult to learn a new language (from JAVA to Node (js) or C # to JAVA) than 10 or 15 years ago, at that time, when vbprogramming and C ++ programming (from VB to C ++), there were very few examples of the syntax of the two. The difference was far greater. Suddenly I found it a little out of the box. Here I leave a foreshadowing. Next time I will write an article dedicated to programming language syntax convergence, learn to write code using general syntax, and become a cool programmer.

Here, I don't want to have too many comments on the programming language. I just want to say that no matter what programming language you are using, it is better to use it, especially some advanced language features and New syntaxes, it makes native programmers feel that you are not a foreigner, and advanced syntax has its specific syntax value, which can improve a lot of efficiency. You can write code without writing a for loop. In the eyes of a real Senior Programmer, all you write is fake code with syntax in other languages.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.