News for hackers. Stuff that matters.
Re:Go says Wat by sacado2 on Friday September 07, 2018 @08:41AM (#17933776)
What typo can that be though? If you wanted to do `if true == x` and typed `if true := x`, the compiler will tell you. If you mistyped your variable name, and wanted to do `tue := false` for instance, but inadvertantly typed `true := false`, the compiler will tell you "true declared and not used". I can't really find a compelling example.
Re:Go says Wat by coldtea on Friday September 07, 2018 @09:43AM (#17934142)
>If you mistyped your variable name, and wanted to do `tue := false` for instance, but inadvertantly typed `true := false`

You don't need to have a variable like "tue" to make such a typo. Since your writing an if statement, you already have "true" and "false" in mind, so you just need to be a little absentminded and voila, instead of foo := false you've written true := false. Plus, lots of naive editors will offer to autocomplete something starting with t to true (if they find the token true used elsewhere within the file).

>the compiler will tell you "true declared and not used".

Only if you don't use it. But a few lines below you could very well be using true legitimately too, in which case it wont tell you:

  true := false
  
  ...

  if condition == true {
    // ...
  }
Re:Go says Wat by sacado2 on Friday September 07, 2018 @10:07AM (#17934305)
> Only if you don't use it. But a few lines below you could very well be using true legitimately too, in which case it wont tell you:

Good point!

Edit: but then, your expected original variable name, `tue` in my example, would be used while not yet defined:

    true := false
    if foo() || bar {
       tue = true  // Compilation error
    }
    ...
    if condition() == true {
       ...
    }
Only possible case I can think of: you already defined tue, but tried to redefine it via variable shadowing:

    tue := true
    ...
    if cond() {
        true := false
        if foo() || bar() {
           tue = true // Will compile, but not the tue you expected
        }
        ...
        if condition == true {
           ...
        }
    }
Re:Go says Wat by SamWhited on Friday September 07, 2018 @08:10PM (#17938618)
The "it's 3AM and I want to write 'myvar := true' and am thinking about 'true' so I write 'true := true' and move on and don't notice" typo.