From: arne@vajhoej.dk   
      
   On 8/19/2025 8:29 AM, Simon Clubley wrote:   
   > On 2025-08-18, Arne Vajhøj wrote:   
   >> On 8/18/2025 3:42 PM, Arne Vajhøj wrote:   
   >>> On 8/18/2025 8:37 AM, Simon Clubley wrote:   
   >>>> 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.   
   >>   
   >> Function calls is a classic example of potential side   
   >> effect, but many languages allow assignments in expressions.   
   >>   
   >> Python 3.8 introduced the walrus operator.   
   >   
   > Then Python has lost the plot. When you do ugly things like this, then   
   > the easier it is for subtle errors to slip in. Also, you write code once   
   > (hopefully), but read it many times.   
      
   Most languages allow the same just using plain assignment (*).   
      
   Two points related to the fact that they have a special   
   operator instead of just using plain assignment.   
      
   1) That it got added later means that there must have been an   
    explicit demand for such functionality unlike plain assignment   
    that could have appeared "by accident".   
   2) That it is a special operator also means that it is easy to   
    search for either by tools or manually making it something to   
    check for in code review.   
      
   *) And not just C. For the first many years of Java's existence, the   
   following was the way to read lines from a file:   
      
   BufferedReader br = ..;   
   String line;   
   while((line = br.readLine()) != null) {   
    ...   
   }   
      
   Arne   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|