Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^2: if statement confusion

by BrowserUk (Pope)
on Jun 11, 2012 at 22:32 UTC ( #975653=note: print w/ replies, xml ) Need Help??


in reply to Re: if statement confusion
in thread if statement confusion

we do need to be able to consistently write easily maintainable code that can be correctly understood at first glance.

Why?

Would you trust

  • a lawyer that took one glance at the deeds to your new house and entreated you to sign on the dotted line?
  • a judge that took one glance at the charge sheet and moved directly to sentencing?
  • a doctor that took one glance at your Xray and gave you his diagnosis?
  • a surveyor that took one glance at the site plans and concluded that the drainage was adequate?
  • An engineer that took one glance at the blueprints for a new braking system and concluded that they were safe?

The source code of a program is the software equivalent of these documents; they are at least as complex, and should require at least as much effort on behalf of the reader as those other documents before rushing to judgements or conclusions.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

The start of some sanity?


Comment on Re^2: if statement confusion
Re^3: if statement confusion
by sundialsvc4 (Abbot) on Jun 12, 2012 at 03:33 UTC

    Honestly, sir, you sometimes pick an argument just for the sake of an argument.   The need to “write easily maintainable code that can correctly be understood at first glance” truly is self-evident ... to the point that nothing further need be said.

      The need to “write easily maintainable code that can correctly be understood at first glance” truly is self-evident

      And that's just the point. It isn't.

      Indeed, any requirement for the content of any technical document to be "understandable at a glance" is completely unjustifiable. At least outside of the classroom.

      It is the software equivalent of soldiers wearing red coats with shiny buttons as they go into battle. It was once deriguer, but long since shown to be detrimental to the primary goals.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      The start of some sanity?

Re^3: if statement confusion
by blackstarr (Pilgrim) on Jun 12, 2012 at 07:00 UTC
    You make a very valid point, but I think you carry the logic too far.

    Yes, I'd always want an expert to be the one handling my contracts, medical diagnosis, etc. But does that mean that they should be made as complex as possible so that ONLY an expert can understand it?

    I'm sure that there are a lot of very good coders out there who can look at a bit of compact code they wrote 2 years ago and see it's purpose and complexities at a glance, however most of us humble mortals need time to figure these things out ... and for us clearly written easily maintainable code is far more important than shaving a femosecond off a CPU operation.

    Hats off to you gurus ... we all want to end up like you ... but we're not there yet, so please don't discourage us by insisting that only compact, complex code is acceptable.

    So Long
    blackstarr

      I am curious to know who exactly you're responding to here.

      The ternary operator is not overly advanced at all. Any Perl programmer who is even low-mid level advanced (at minimum) can see it in a heartbeat. If you haven't seen it before, it may often be seen multi-line like this:

      $ans = 6 < 8 ? 'true' : 'false';

      ..or even like this:

      $ans = ( 6 < 8 ) ? 'true' : 'false';

      for precedence sake (as shown in the man page). Going off as you have is ridiculous. You say "there are a lot of very good coders out there who can look at a bit of compact code they wrote 2 (sic) years ago and see it's (sic) purpose and complexities at a glance" and then you say "however most of us humble mortals need time to figure these things out...".

      First, I am but a humble mortal, and I don't even consider myself a good coder, but I sure can remember this type of snippet with no question. Not only that, but I'm willing to bet that any one of my 'humble mortal' monks who have been around even as long as I have would know what this type of *idiom* looks like.

      I don't normally call someone out like this, but wow, who are you trying to defend, and more importantly... do you realize who you're putting down?

      ps. If you want something more simplistic, ask for it. If you *know* there is something more simplistic, why are you complaining... seems to me that if you know in advance, you must know for yourself.

      what are you looking for... this?

      if (a){ b; } else { c; }

      I just went through every one of your past posts, and it appears to me as though you're just a 10 year old sock fscking puppet that has 20 posts you decided to dredge up.

      Not ONE of your past posts as this person has any code whatsoever, so why would you decide to dig up an old alias to attack?

      Making yourself look worse homie.

        Err ... why the aggression?

        My apologies if I've offended you, but as my comment wasn't even directed at you I don't see why you should get insulting about it.

        1.) I only have this one handle ... If I wanted to stay unknown I'd post as anonymonk

        2.) I wasn't commenting on the actual code at all ... I'd never presume to do that because I KNOW I'm not good enough.

        3.) I wasn't attacking anyone, I wasn't being sarcastic, I was stating an honest opinion ... or do I have to be vroom before I am allowed that?

        4.) My comment was 100% aimed at the BrowserUK's idea that there is no need for easily readable and maintainable code, it had nothing to do with the actual code under discussion. It also had nothing to do with any personal opinion of BrowerUK and his abilities as a coder ... I've read enough of his posts to know he's way better at perl than I'll ever be. My difference is purely philosophical, not personal.

        So Long
        blackstarr
      Yes, I'd always want an expert to be the one handling my contracts, medical diagnosis, etc. But does that mean that they should be made as complex as possible so that ONLY an expert can understand it?

      No. But then, I never suggested that. Requiring more than "a glance" is not the same as "complex as possible".

      And suggesting that every program should be written so as to be understandable by the most inexpert of programmers is a crock.

      Eg. There are some algorithms that are very cleanly and concisely described using recursion, that require verbose, intricate and vastly more complex descriptions when done without it.

      But there are quite a few "programmers" -- including some I've encountered in quite senior positions with 'many years of experience' -- who simply cannot 'get' recursion. Avoiding recusion because there are some people that will never get it is ridiculous.

      Finally, there is nothing "complex" or "difficult" about the ternary statement:

      my $var = cond ? constantA : constantB;
      , which is where this subthread got started.

      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      The start of some sanity?

Re^3: if statement confusion
by DrHyde (Prior) on Jun 13, 2012 at 10:38 UTC
    $ans = something ? 'true' : 'false' is the equivalent not of the deeds for a house, but of a single clause, or a single sentence. Each sentence in the deeds should be easy to understand.
      $ans = something ? 'true' : 'false' is ... a single sentence. Each sentence in the deeds should be easy to understand.

      Agreed (with caveats*). So, then the question becomes: do you (we; perl programmers in general) find the ternary operator -- used correctly -- easy to understand?

      Given that I found multiple uses of the ternary operator in each of 4 (out of 5 chosen at random) of your distributions that I looked into, I'd assume that you do. So do I. And so do (on the basis of anecdotal evidence) a substantive majority of Perl programmers.


      (*)Caveats: Deeds, like many other legal documents, contain many terms and 'set phrases' that do not crop up in any other circumstance. A few examples drawn from the deeds of my house:

      Any easement or quasi easement right or privilege whatsoever over or against the Transferor's adjoining or adjacent property or any part or parts thereof other than any rights herebye granted
      (but without prejudice to the generality of the foregoing)
      not to use or occupy any such dwellinghouses for any purpose other than the occupation of each dwellinghouse by one family at one time.

      The phrases, despite their wordiness, are actually shorthand, that convey far more extensive and more precisely defined meaning than is apparent from the sum of their words. That meaning is conveyed not by their wording, but rather by the years -- in some cases, centuries -- of use and reuse, and of trial and retrial in the courts; and so are proven to constitute their precise meaning through case law. (Update: Think idioms.)

      That is nothing more than an (I hope, interesting) aside, but it makes a specific case for the general point that technical documents, whatever their type, will contain nomenclature the meaning of which will not be immediately (at a glance), obvious to those unfamiliar with it.

      To the unknowing outsider or beginner in the field, these nomenclatures may seem complex and unclear, but they are usually quite the opposite once you understand their purpose. And understanding their purpose is nothing more than a matter of becoming familiar with them, and practice. Ie. You have to learn them.

      These nomenclatures crop up in every professional field; but only in programming is there a generally pervading notion that they should be avoided to lessen the learning curve for beginners and those less willing to extend themselves.

      Lawyers are required to do 4(?) years of advanced, specialist education before they can practice; and then accumulate many more years of both learning and experience before they can progress to barrister; more years still before they can become QCs; and more after that before becoming judges.

      There is similar requirement for both practical experience and ongoing learning for doctors; engineers; surveyors; physicists; chemists etc.

      Of the professions, only programmers can start to practice after a 12-week course in some archaic teaching language at college; and only programmers seem happy to devalue their skills and learning, by advocating the output of their years of experience should "understandable at a glance" by any oik that knows how to load the source code into an editor to view it.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      The start of some sanity?

Re^3: if statement confusion
by apotheon (Deacon) on Jun 15, 2012 at 17:29 UTC

    I think you are creating a problem where none exists. The point does not seem to be about whether a reader merely glances at something and proclaims understanding; rather, it is about whether the writer strives to make things clear to the reader. Thus, it is not about a lawyer who merely glances at a contract then asks a client to sign on the dotted line, but rather about someone writing a contract to be clear rather than to be opaque and full of gotchas.

    Would you trust a lawyer who wrote contracts as though paid by the letter rather than as though paid for agreeable results? Would you, likewise, trust a lawyer who argued your case in court as though paid by how long he could make your trial last rather than as though he would only be paid if you were acquitted of all charges? What about a doctor who was paid based on how many different pharmaceutical companies' products he injected into you, rather than based on positive benefit to your health?

    I prefer a programmer who writes clear code over a programmer who either plays golf with production code or bases his or her self-worth as a programmer on the number of clever tricks crammed into a simple function.

    print substr("Just another Perl hacker", 0, -2);
    - apotheon
    Licensed OWL by Chad Perrin

      but rather about someone writing a contract to be clear rather than to be opaque and full of gotchas.

      Here's the rub. Life isn't like that. If all contracts were fair, we wouldn't need them, or lawyers to prepare them or vet them.

      I want a lawyer who doesn't take the contracts I ask him to vet before I sign them at face value. Who doesn't judge the correctness of the contract on the basis of it containing short sentences and few polysyllabic words.

      I want a lawyer that understands the Terms of Art, and the significance of the presence or absence in a contract. I want him or her to know what they are doing; to understand the importance and significance of the terminology (or lack thereof) in the contract and advise me accordingly; and I want a lawyer that will take full responsibility for their advise should the contract be (or need to be) challenged in court.

      And I want programmers to recognise that restricting themselves to a "simple" subset of their programing languages, doesn't make their programs "clear"; it makes them verbose. And the more lines of code you write; the more bugs you will generate.

      And all your use of words like "clever", "tricks" & "golf" are convenient but meaningless screens for the lazy and incompetent to hide behind.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      The start of some sanity?

        My point was not to suggest that life is fair, or that one should always take contracts at face value. It was to point out that the preceding person's point (while poorly presented) was about the fact that the guy writing the code should try to make the code clear. Your analogy to contractual law is looking at the wrong side of the transaction, talking about the behavior of the reader rather than that of the writer.

        Obviously, code should be correct, first and foremost -- but within that constraint, it should also be as clear as reasonably possible. There's no necessity to limit oneself to a simplistic subset of a language to achieve that (and I agree with the entire paragraph in which you mentioned opposition to that notion), in the general case, and I even agree that in this case it makes sense to use a clarified and correct ternary operator, but I disagree with your approach of disputing the statement that one should strive to write clear code.

        I also think you're now manufacturing disagreement with me where it does not actually exist, when denigrating my character (apparently on the basis of the fact that you're feeling defensive).

        In the end, the lawyer analogy is a poor one for this situation, no matter what point you're trying to make. The motives, incentives, and circumstances surrounding contracts and software applications are simply too different, and I should have avoided using your analogy to try to make my point. I also should have said that I thought you were creating disagreement where none essentially existed, rather than a problem. Here we see that clarity in English is important, just as it is in Perl.

        print substr("Just another Perl hacker", 0, -2);
        - apotheon
        Licensed OWL by Chad Perrin

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://975653]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (10)
As of 2014-12-19 11:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (78 votes), past polls