From: arne@vajhoej.dk   
      
   On 8/18/2025 8:37 AM, Simon Clubley wrote:   
   > On 2025-08-15, Arne Vajhøj wrote:   
   >> In general I like the idea of writing code in a way that does   
   >> not require the reader to have memorized ten thousand things from   
   >> the language spec.   
   >>   
   >> But I do not consider this a matter of remembering the specific   
   >> details about an operator - I consider this a matter of remembering   
   >> what operator a symbol represent.   
   >>   
   >> I consider "short circuiting AND" and "non short circuiting AND"   
   >> to be two different operators.   
   >   
   > They are not. One is a subset of the other and both carry out the   
   > same core operation.   
   >   
   >> And in C then && is the first operator not the second operator.   
   >>   
   >> And understanding what operator each symbol represent is not   
   >> detail but core. IMHO.   
   >>   
   >   
   > I disagree. Strongly. Both operators do exactly the same thing which   
   > is to implement a logical AND. Code written using this operator   
   > generates exactly the same logical AND result regardless of whether   
   > short circuiting is in use or not.   
   >   
   > In addition however, a short circuiting compiler generates code to   
   > stop evaluation if the previous logical AND subexpression was false.   
   > This is a feature of the compiler and does not turn logical AND into   
   > something which does something other than logical AND.   
      
   Considering two operators the same because the functionality of one is   
   a subset of the functionality of the other seems unlogical to me.   
      
   C += vs C =   
   PHP == vs PHP ===   
   etc.   
      
   > It is _always_ safe to write code which assumes short circuiting is   
   > not in use and it will work exactly the same even in the presence   
   > of a compiler which generates short circuiting code.   
      
   Not true.   
      
   Not if the second expression has side effects.   
      
   I am sure that you don't want expressions with side effect. But   
   it happens.   
      
   > It's all about writing robust code, not clever code. My approach   
   > generates much more robust code, especially when you might translate   
   > the code to another language that does not implement short circuiting   
   > and you don't realise this during the translation.   
      
   I agree with the philosophy in general.   
      
   But I have little faith in trying to translate from one language   
   to another language without deep understanding of operators in the   
   two languages.   
      
   Arne   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|