News for hackers. Stuff that matters.
Re:How well do you know C++ auto type deduction? by xnorswap on Monday December 15, 2025 @04:27AM (#46272161)
The guidelines I follow for C# has "use var where it's obvious, but explicitly type when not".

So for example I'd write:

  var x = new List<Foo>();
Because writing:

  List<Foo> x = new List<Foo>();
Feels very redundant

Whereas I'd write:

  List<Foo> x = FooBarService.GetMyThings();
Because it's not obvious what the type is otherwise ( Some IDEs will overlay hint the type there though ).

Although with newer language features you can also write:

  List<Foo> x = new();
Which is even better.
Re:How well do you know C++ auto type deduction? by tcfhgj on Monday December 15, 2025 @05:07AM (#46272485)
I would rename `x` to `foos` and jump to the function/use IDE hints for the exact type when needed.
Re:How well do you know C++ auto type deduction? by Leherenn on Monday December 15, 2025 @07:03AM (#46273394)
Right, although I would argue the most interesting part of the type here is the container, not the containee.

With good naming it should be pretty obvious it's a Foo, and then either you know the type by heart, or will need to look up the definition anyway.

With standard containers, you can have the assumption that everyone knows the type, at least high level. So knowing whether it's a list, a vector, a stack, a map or a multimap, ... is pretty useful and avoid a lookup.

Re:How well do you know C++ auto type deduction? by Aeglaecia on Monday December 15, 2025 @05:27AM (#46272633)
an interesting demarcation of subjective mental encapsulation ... associating the anonymous type of a buffer with the buffer's name ... as opposed to explicitly specifying the type of an anonymously named buffer
Re:How well do you know C++ auto type deduction? by lan321 on Monday December 15, 2025 @10:09AM (#46275467)
I usually prefer

    List<Foo> x = new();
since it gives me better alignment and since it's not confused with dynamic.

Nowadays I only use

    var x = new List<Foo>();
in non-merged code as a ghetto TODO if I'm considering base types/interface.