News for hackers. Stuff that matters.
Re:Don’t use C++ auto? Restricting auto is not the best deci... by raverbashing on Thursday November 09, 2017 @10:11AM (#15663014)
This shouldn't even be up to discussion. Auto is better overall

Compilers know types better than humans.

Whoever bans it (whithout a very, very compelling reason like "some of our code has to compile in an old compiler") is being a luddite at best.

This should have been in C++ from its inception to be honest, to avoid blah_type<with_this> something = new blah_type<with_this>() repetition.

Re:Don’t use C++ auto? Restricting auto is not the best deci... by pjmlp on Thursday November 09, 2017 @10:26AM (#15663149)
> This should have been in C++ from its inception to be honest

It was, but the backslash was even greater back then, so Bjarne removed it from C with Classes.

There are a few presentations/interviews where he mentions it.

Re:Don’t use C++ auto? Restricting auto is not the best deci... by cjensen on Thursday November 09, 2017 @11:05AM (#15663493)
That was an entirely different auto. In C89, auto just "variable on the stack". It still had a type. The new auto is just borrowing the keyword since it (a) makes sense and (b) is already a reserved word.
Re:Don’t use C++ auto? Restricting auto is not the best deci... by pjmlp on Thursday November 09, 2017 @11:10AM (#15663539)
How the keyword was named when Bjarne introduced it doesn't matter, the purpose was the same as C++11 auto.
Re:Don’t use C++ auto? Restricting auto is not the best deci... by Shorel on Thursday November 09, 2017 @12:42PM (#15664271)
It was entirely another concept.

Before C++11 auto meant it was not static, extern or register, and in fact every single variable was already implicitly auto if no specifier from the previous list was applied.

    int n = 10;
In that line, n was auto. Now it is not auto, only int.
Re:Don’t use C++ auto? Restricting auto is not the best deci... by pjmlp on Thursday November 09, 2017 @12:48PM (#15664312)
Type inference is orthogonal to whatever keyword is used.

Bjarne used another keyword in C with Classes, removed it due to backslash, and the commite decided to re-purpose auto for the same purpose in C++11.

No big deal, the meaning of static is also context dependent, and no one is fighting against it like it happens with the new meaning for auto.

Re:Don’t use C++ auto? Restricting auto is not the best deci... by megaman22 on Thursday November 09, 2017 @10:47AM (#15663338)
> This should have been in C++ from its inception to be honest, to avoid blah_type<with_this> something = new blah_type<with_this>() repetition.

Type inference for this is about the only way to make "enterprisey" C#/Java code palatable.

The only problem is if you're a .NET shop that is a little crusty, and people start having PTSD flashbacks and conflate the C# type inferred "var" with the old VisualBasic monstrosity Variant type.

Re:Don’t use C++ auto? Restricting auto is not the best deci... by memsom on Monday November 13, 2017 @07:03AM (#15685873)
Personally, I wee it more like the bad old days before "Option explicit" and "Option strict" being turned on and every variable being declared as "dim x" with no type. Sure, that then used a variant in the background, but the chaos it installed is what scares the crap out of some shops with regards to "var" and C#. If you were a good VB.Net citizen, you always newed up your variables like : "dim x as new Y()".
Re:Don’t use C++ auto? Restricting auto is not the best deci... by baby on Thursday November 09, 2017 @10:27AM (#15663155)
Agree, Golang has := by default
Re:Don’t use C++ auto? Restricting auto is not the best deci... by maxxxxx on Thursday November 09, 2017 @10:55AM (#15663407)
I don't know Go. What does := do?
Re:Don’t use C++ auto? Restricting auto is not the best deci... by Nvorzula on Thursday November 09, 2017 @11:19AM (#15663608)
x := some_code_here says "x is a NEW variable whose type is whatever the result of the expression on the right hand side is".

Say we have a function, GetInt64(), which...returns an int64. x := GetInt64() both declares x to be an int64 and places the resulting value of the right hand side into x. If x was already to declared to be an int64, E.G.:

var x int64

x := GetInt64()

Then the compiler complain that x is not new - it has already been declared. In this case you have to omit the colon to remove the fancy "auto" semantics.

var x int64

x = GetInt64()

Re:Don’t use C++ auto? Restricting auto is not the best deci... by memsom on Monday November 13, 2017 @10:03AM (#15686915)
That looks a lot like the old Pascal assignment vs equivalence operators. In Pascal (read Delphi) we had '=' for equality and ':=' for assignment. So:

x = 5 <-- a boolean statement, true if x equ 5

x := 5 <-- an assignment of the value 5 to the var x.

TBH, it's only like '=' vs '==' in C like languages. But it's easier to spot errors, as Pascal can never have a valid statement where the two are used in the wrong way.

Re:Don’t use C++ auto? Restricting auto is not the best deci... by maxxxxx on Thursday November 09, 2017 @11:34AM (#15663757)
Interesting. Seems I should take a look at Go.
Re:Don’t use C++ auto? Restricting auto is not the best deci... by baby on Thursday November 09, 2017 @07:25PM (#15666970)
You also usually declare stuff using this.

For example

    a := "hello"
or

    a := 0
or

    a := []byte{0, 1}
Re:Don’t use C++ auto? Restricting auto is not the best deci... by _sdegutis on Thursday November 09, 2017 @11:13AM (#15663564)
Implies the new variable's type to be the return type of the assigned expression.