DOCX

Why do you say to select the correct programming language is very important, and how to choose the right

By Ricky Warren,2015-03-20 16:35
9 views 0
Why do you say to select the correct programming language is very important, and how to choose the right

    Why do you say to select the correct programming language is very important, and how to choose the right

    A few months ago, a colleague asked me, how should choose the programming language, or what the choice of a fixed pattern, at that time I was going to write something.The meeting last week in silicon valley, this is the first time I talk to "hack3rs" serial entrepreneur and geeky.Unheard of dirty words, I learned a lot also have - even pursue leanstartups tend to put the question too complicated.

    Will it is not difficult to understand the people of lean spirit identified.Google, Facebook and's lecture trainers are attractive.From a more macro perspective and solve the problem.Has nothing to do with the company's financial resources, the scale, they deliberately cut off details, in order to focus their attention on the root of the problem.

    I had always demand myself even consider using a high-level programming language under fully to the object language, I found that many of the new era ofstart-ups also haven't understand its essence.They use Javascript, Python and Ruby programming, but don't know why want to use the language.

    There is no denying the fact that the compact loop written or avoid using its inherent template.But if this is the only reason you choose a programming language, then you are wrong.In daily work, rather than use vectorization based on depth optimization multi-core parallel asynchronous map - c + + language constructs the reduce architecture to do a convolution discrete Fourier transform (the correlation - DFT), I prefer to use the BASIC for a fast Fourier transform (FFT).

    So what should choose according to what programming language?The only testing standard: whether and projection.

    Despite the execution efficiency and function of language and so on, a language must be able to let you describe your intention, not just for the compiler, but also for the future in terms of the reader.I believe that 99% of the questions in the software maintenance are due to the first to write code didn't ready to express their intentions.If speech is not fluent, the document is not document.If speech is not fluent, UML diagram is a UML diagram.If unable to describe a certain data type which is suitable for operator, object-oriented programming, it is not object-oriented programming.However, feeling not referring to the C style ModifyWindowEx (HWND WND) is not easy to read and Window. The modify and

    compiler () has told you this Window can be and what not to do.The key is to show that your intention.

    Fortran is now far behind, because it is in this way to describe a formula:

MOV AX, $5D

    ADD AX, $6F

    MOV $7F, AX

    It is can be written as such:

    c = a + b

    So you know it's a plus b, results from c, even if you don't understand the computer can understand.

    Is a common misconception: functional programming language to express what you want, what you want) and imperative programming language to express how do you want to (how you want).

    This is a bad understanding.Because sometimes "how do you want to" is exactly what you want to express meaning.

    According to my consistent style of post, please ask yourself a fundamental problem, when faced with the choice of language:

    "If I clarify meaning?"

    If you can't answer this question, you use the best language.If you have to write documents or make comments, this suggests that your code can not describe your intentions.Look at the function prototype:

    char* reverseString(const char *foo);

    In the absence of about null pointer, the empty string and other exception handling documents, with the help of can't understand it at the author really want to do.It's not so good.Function within may, of course, the input validation performed countless, but you have to write a bunch of unit tests for a wide variety of specific input to ensure that your assumption is correct.

    What I mean by "clarify meaning" what meaning be?Assume that a c + + supports the following in the prototype virtual grammar:

    char* @Nullable reverseString(@NonNullable const char *foo);

    In the function prototype with the annotation has two advantages:

    1. You don't need to test beforehand foo is null or not.The compiler to ensure will give you a not null.

    2. Clearly tell the caller you don't put up with null.This way of expression compiler is able to understand, good static analysis tool can detect this kind of bug, this is the C language.

    Although it seems only is to enhance the syntax, the actual not only that, it also enhances the semantics.So either man or machine will understand foo this variable is not null, or function is very angry, the consequences will be severe.And, you give this function to draw the line, then can don't have to worry about foo is null.

    Not all, functional programming:

    Everyone of my another common misconception is that I praise highly pure functional languages.I do have reason to like them.See the above formulas?

    c = a + b

    If I want to have expr1 and expr2 values in how to express?

    c = (expr1) + (expr2)

    If you have any additional expr1 operation and affect expr2 value and how to express?It is not rare:

    c = (a++) + (a + b);

    The problem here is not what you think.I know what you're thinking: "god knows how this language will explain this formula. Computing the order of one thousand?"

    Do you want to wrong.Because people can produce that thought, programming languages will have such characteristics.To answer your question is very simple, look at compile manuals.

    The above formula's fundamental problem is that I don't know that calculation sequence is accidental or intentional.I know exactly formulas on it will do, but I'm not sure that it intends to calculate the order?I can optimize the formula and put it on a loop?Can I cut in multicore multi-threading is it?If someone asked me, if give z value 10 instead of 20, will affect the value of c, I can't answer.

    In theory is unable to answer the question above.Of course we can do it according to the experience and some assertions (an assertion).'s assertion that after a pile or a warning, said rationally, we still don't know z will affect a or b, ultimately affect the c.

    Why is this important

    The maintainability of the code is based on the code to be able to read on the basis of sex.Do you know why CSS is bad?If it's just programmers write wrong or confusing the designer put the font and layout rules, the earth person all know that it's not too bad.CSS is

    bad in bad if not add a lot of comments, people will not be able to understand the code through the literal meaning of intention.

    Don't forget to rule-based declarative language is not a new concept, more is not revolution.50 years ago Prolog provides similar CSS declarative way.Today the Erlang also offers this kind of way, and is widely used in the industry.

    Please see the following line of code:

    div .title #subtitle {color: blue}

    If don't try to load, I bet you fully believe that what kind of an effect on the page.Literally couldn't see the relationship with other rules completely, also can't see it how to deal with match conflict.

    For thou shalt Ruby/Python/Node. Js programmers, my suggestion is that if you really want to be free from vulgarity, learn from Google and Facebook.They use some experimental technology, is not to replace the for loops, but used to show the for - the intention of the loops.Rapid prototyping choose simple language, when need to accurately describe the intent to consider replacement programming language.

    The necessity of imperative languages:

    Finally, I want to explain why imperative languages is necessary.Look at the following example this driver:

setlpt1(00000000b);

setlpt1(00010000b);

setlpt1(00000000b);

    This is my imaginary serial command protocol.This is a few lines of code in accordance with the order.Even 200 years later, what their intentions will not occur.Necessary when using the command language, explicitly tell the reader not to disturb the code.You should not change their order.You don't use them on some abstract port, they are only applicable to a serial port or so-called printer port.

    Use functional language to achieve the above functions, and combined with synchronization primitives to ensure that they are run in sequence, is foolish.

    Conclusion:

    If there is a little bit to this article summary the thing, that is: the next time you write any code/specification/procedure, ask yourself, clearly expressed intention?The future maintainers to see what you wrote, if you can understand it

Report this document

For any questions or suggestions please email
cust-service@docsford.com