Click here to Skip to main content
15,566,366 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
JokeRe: Whose idea was this in C\? Pin
Randor 16-Mar-22 12:01
professional Randor 16-Mar-22 12:01 
GeneralRe: Whose idea was this in C\? Pin
Keefer S17-Mar-22 3:51
Keefer S17-Mar-22 3:51 
PraiseRe: Whose idea was this in C\? Pin
Randor 17-Mar-22 6:05
professional Randor 17-Mar-22 6:05 
GeneralRe: Whose idea was this in C\? Pin
Kate-X25717-Mar-22 5:57
Kate-X25717-Mar-22 5:57 
GeneralRe: Whose idea was this in C\? Pin
Greg Utas17-Mar-22 7:00
mveGreg Utas17-Mar-22 7:00 
GeneralRe: Whose idea was this in C\? Pin
Ralph Trickey17-Mar-22 12:31
Ralph Trickey17-Mar-22 12:31 
GeneralRe: Whose idea was this in C\? Pin
Greg Utas17-Mar-22 12:48
mveGreg Utas17-Mar-22 12:48 
GeneralRe: Whose idea was this in C\? Pin
Dave B 202217-Mar-22 4:31
Dave B 202217-Mar-22 4:31 
Quote:
var is like auto in C++, right?


I used to think that. But I am not so sure anymore in terms of the net effect in each language.

In our C# code, I demand that the type be determinable by reading the line the type is defined on. I.e. if a variable is initialized by a value returned from a method, you best not use var. The reasoning is not that a developer can't determine the type with enough effort. It is the time it takes someone reading the code to KNOW what the code is doing and meant to do. At the end of the day it is about developer productivity. Experienced developers aren't questioning if they can make something work or focusing on the time it takes to key in their code. It is how effective they are at solving problems and maintaining volumes of code. Using var is optimizing the writing of code at the expense of the total cost of the code over the life of the code.

But, when moving over to C++ and understanding the design best practice of (Always Use Auto), I had to step back and evaluate why someone would recommend a coding pattern that made code take longer to understand and would drop developer productivity.
In the end, I came to the conclusion that the C# patterns that we tend to use don't use structs, almost always use classes, and as a result, put the memory on the heap. In these scenarios there is no runtime benefit the compiler can help you with that makes your code more effective since all non primitive variables are just references. var only gives an opportunity to save time typing code at the expense of maintaining it.

C++ on the other hand appears to prefer patterns where local variables do not use the heap and the compiler is both optimizing the implicit type conversion and if it can use a reference instead of a copy with every variable use. In the patterns I am aware of, it is minimizing the copying of data and the running of class move/copy/ctor/dtor methods for you. Without using auto here, the compiler's hands have been tied.

All of that being said, I would like the input of those who have written a lot of modern C++ to see if I am missing anything.

I also believe that if our C# code used structs that had implicit type conversions more, the reasoning of not allowing var may be misguided. Although I have not pulled on this thread and do not know much about the C# compiler optimization in these cases.
GeneralRe: Whose idea was this in C\? Pin
Greg Utas17-Mar-22 4:54
mveGreg Utas17-Mar-22 4:54 
GeneralRe: Whose idea was this in C\? Pin
Dave B 202217-Mar-22 6:31
Dave B 202217-Mar-22 6:31 
GeneralRe: Whose idea was this in C\? Pin
Greg Utas17-Mar-22 6:55
mveGreg Utas17-Mar-22 6:55 
GeneralRe: Whose idea was this in C\? Pin
Kate-X25717-Mar-22 5:57
Kate-X25717-Mar-22 5:57 
GeneralRe: Whose idea was this in C\? Pin
Slacker00716-Mar-22 6:39
professionalSlacker00716-Mar-22 6:39 
GeneralRe: Whose idea was this in C\? Pin
JustDre17-Mar-22 8:05
JustDre17-Mar-22 8:05 
GeneralRe: Whose idea was this in C\? Pin
TNCaver16-Mar-22 7:16
TNCaver16-Mar-22 7:16 
GeneralRe: Whose idea was this in C\? Pin
Ralph Trickey17-Mar-22 13:22
Ralph Trickey17-Mar-22 13:22 
GeneralRe: Whose idea was this in C\? Pin
Kate-X25717-Mar-22 5:57
Kate-X25717-Mar-22 5:57 
GeneralRe: Whose idea was this in C\? Pin
Kirk 1038982117-Mar-22 5:27
Kirk 1038982117-Mar-22 5:27 
GeneralRe: Whose idea was this in C\? Pin
Dave B 202217-Mar-22 7:34
Dave B 202217-Mar-22 7:34 
NewsInteresting article on the future of Wordle Clones, Archives, and Word List Pin
Slacker00716-Mar-22 1:26
professionalSlacker00716-Mar-22 1:26 
GeneralRe: Interesting article on the future of Wordle Clones, Archives, and Word List Pin
dan!sh 16-Mar-22 1:54
professional dan!sh 16-Mar-22 1:54 
GeneralRe: Interesting article on the future of Wordle Clones, Archives, and Word List Pin
Ravi Bhavnani16-Mar-22 5:51
professionalRavi Bhavnani16-Mar-22 5:51 
GeneralRe: Interesting article on the future of Wordle Clones, Archives, and Word List Pin
Kirk 1038982117-Mar-22 10:06
Kirk 1038982117-Mar-22 10:06 
GeneralRe: Interesting article on the future of Wordle Clones, Archives, and Word List Pin
den2k8816-Mar-22 3:18
professionalden2k8816-Mar-22 3:18 
GeneralRe: Interesting article on the future of Wordle Clones, Archives, and Word List Pin
Ravi Bhavnani16-Mar-22 5:50
professionalRavi Bhavnani16-Mar-22 5:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.