News for hackers. Stuff that matters.
Re:CLion Nova Explodes onto the C and C++ Development Scene by OnionBlender on Thursday November 09, 2023 @11:12AM (#38206880)
Some teams discourage it because it makes code reviews a little harder. I worked on a team that allowed it for obvious things like iterators or std::make_unique<>.

From Google's C++ Style Guide:

https://google.github.io/styleguide/cppguide.html#Type_deduc...

> The fundamental rule is: use type deduction only to make the code clearer or safer, and do not use it merely to avoid the inconvenience of writing an explicit type. When judging whether the code is clearer, keep in mind that your readers are not necessarily on your team, or familiar with your project, so types that you and your reviewer experience as unnecessary clutter will very often provide useful information to others. For example, you can assume that the return type of make_unique<Foo>() is obvious, but the return type of MyWidgetFactory() probably isn't.

I would typically use auto while working on something but then have to replace many of them before creating a code review. I wish Visual Studio could do that, it clearly already knows the type.

Re:CLion Nova Explodes onto the C and C++ Development Scene by dataflow on Thursday November 09, 2023 @11:16AM (#38206951)
> Some teams discourage it because it makes code reviews a little harder

Not just reviews, but anything that involves reading the code (which is frequently usage and maintenance). Swimming in a file where everything is auto is a special kind of hell. It's like having no firm ground to step on.

Re:CLion Nova Explodes onto the C and C++ Development Scene by mxz3000 on Thursday November 09, 2023 @11:37AM (#38207234)
I would expect most people to read code in their IDEs, where small amounts of type inference like this is fine because the IDE tells you what the type is.

I agree that if you spend a lot of time reading code in something like GitHub, not having explicit types is annoying, but seriously, who does that?

Re:CLion Nova Explodes onto the C and C++ Development Scene by katbyte on Thursday November 09, 2023 @11:46AM (#38207365)
Well pr reviews are usually don’t in gh or other web platform so, many people?
Re:CLion Nova Explodes onto the C and C++ Development Scene by menaerus on Thursday November 09, 2023 @11:53AM (#38207464)
I can come up with a few more examples.

- No review tool is capable of providing type inference hints.

- Not everybody's development workflow consists of using the IDEs.

- Development/debugging on remote machines does not even have a GUI to start with - so no IDEs there as well.

Re:CLion Nova Explodes onto the C and C++ Development Scene by layer8 on Thursday November 09, 2023 @12:23PM (#38207924)
If the IDE only displays the type on hover, that’s a significant usability regression.

It also makes it harder to grep for usages of any given type. Of course IDEs could help with that too, but I don’t know any that provide that functionality.

Re:CLion Nova Explodes onto the C and C++ Development Scene by dataflow on Thursday November 09, 2023 @01:11PM (#38208526)
IDEs don't always display every type in a useful way. Sometimes they just display an unhelpful alias which ends up being just as useless. Sometimes they display an incredibly verbose version with all the default template parameters written out, making it a nightmare. Sometimes they give useless results, like when you have a dependent type whose concrete type you know (imagine typename T::value_type vs. size_t). Sometimes they haven't even finished analyzing the code yet. I could go on. You should not be crippled without your IDE.
Re:CLion Nova Explodes onto the C and C++ Development Scene by fluoridation on Thursday November 09, 2023 @01:44PM (#38209083)
>You should not be crippled without your IDE.

Can you compute elementary functions by hand? Why not? Why are you crippled without semiconductors? This attitude leads to never being able to use better tools. We can't leverage an IDE because then we're "crippled" when we don't have it, so we continue writing code as if it was the '70s and the best we have is ed.

Re:CLion Nova Explodes onto the C and C++ Development Scene by fotta on Thursday November 09, 2023 @11:24AM (#38207074)
it's like trying to read untyped python code, which is my personal hell
Re:CLion Nova Explodes onto the C and C++ Development Scene by hardware2win on Thursday November 09, 2023 @11:30AM (#38207148)
I do wonder, you arent using IDE?
Re:CLion Nova Explodes onto the C and C++ Development Scene by _aavaa_ on Thursday November 09, 2023 @11:44AM (#38207333)
In my experience even something like Pycharm can't inference types properly across function boundaries unless you explicitly provide type hints.
Re:CLion Nova Explodes onto the C and C++ Development Scene by hardware2win on Thursday November 09, 2023 @01:16PM (#38208611)
But hes talking about cpp
Re:CLion Nova Explodes onto the C and C++ Development Scene by _aavaa_ on Thursday November 09, 2023 @03:04PM (#38210390)
I misunderstood you I guess. I thought you meant using an IDE to infer the types for untyped Python.
Re:CLion Nova Explodes onto the C and C++ Development Scene by vincnetas on Thursday November 09, 2023 @11:47AM (#38207385)
One could be reading from browser (git/hub/lab)
Re:CLion Nova Explodes onto the C and C++ Development Scene by linhns on Thursday November 09, 2023 @12:01PM (#38207583)
I used to despise auto as well but with new standards it’s just powerful. It’s better to truly understand how type deduction works, you’re gonna be a much better C++ programmer.
Re:CLion Nova Explodes onto the C and C++ Development Scene by dataflow on Thursday November 09, 2023 @01:04PM (#38208453)
> It’s better to truly understand how type deduction works, you’re gonna be a much better C++ programmer.

I understand how type deduction works just fine, thank you. Your assumption that I (or many others) have this stance based on some lack of understanding of how type deduction works is extremely wrong, and completely missing the arguments people are actually making.

Re:CLion Nova Explodes onto the C and C++ Development Scene by mempko on Thursday November 09, 2023 @11:52AM (#38207450)
Google's C++ style is not great and seems to be mostly designed so that Google engineers can maintain Google's vast legacy C++ code-base and maintain consistency.

I wouldn't use it for my project or any new project. It's out of date with how everyone else codes C++.

Re:CLion Nova Explodes onto the C and C++ Development Scene by dlivingston on Thursday November 09, 2023 @12:35PM (#38208076)
What would you recommend as a modern alternative?
Re:CLion Nova Explodes onto the C and C++ Development Scene by mempko on Thursday November 09, 2023 @02:42PM (#38210025)
The C++ Core Guidelines by Sutter and Stroustrup

https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines

Re:CLion Nova Explodes onto the C and C++ Development Scene by Xeamek on Thursday November 09, 2023 @02:40PM (#38209988)
Any specific criticisms?
Re:CLion Nova Explodes onto the C and C++ Development Scene by pjmlp on Friday November 10, 2023 @02:34AM (#38216175)
Basically it contradicts most well regarded C++ books and ISO proposed guidelines, as means to fit Google's culture towards C++.
Re:CLion Nova Explodes onto the C and C++ Development Scene by __jem on Thursday November 09, 2023 @12:37PM (#38208096)
> the return type of MyWidgetFactory() probably isn't.

Isn't the return type of a widget factory method obviously Widget? This doesn't seem like a great example. Of course the method name could be wrong and not enforced at the language level like something between angle brackets, but idk.