Click here to Skip to main content
14,327,765 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.
 
GeneralRe: Modern C++ auto Pin
#realJSOP23-Apr-19 7:58
mve#realJSOP23-Apr-19 7:58 
GeneralRe: Modern C++ auto Pin
Member 916705724-Apr-19 0:34
memberMember 916705724-Apr-19 0:34 
GeneralRe: Modern C++ auto Pin
ceduardodfernandes24-Apr-19 2:15
memberceduardodfernandes24-Apr-19 2:15 
GeneralRe: Modern C++ auto Pin
Member 916705724-Apr-19 2:18
memberMember 916705724-Apr-19 2:18 
GeneralRe: Modern C++ auto Pin
Rick Shaub24-Apr-19 6:32
memberRick Shaub24-Apr-19 6:32 
GeneralRe: Modern C++ auto Pin
OriginalGriff23-Apr-19 5:57
protectorOriginalGriff23-Apr-19 5:57 
GeneralRe: Modern C++ auto Pin
GuyThiebaut23-Apr-19 6:39
professionalGuyThiebaut23-Apr-19 6:39 
GeneralRe: Modern C++ auto Pin
Theraot24-Apr-19 1:35
memberTheraot24-Apr-19 1:35 
If your code has a lot of 'technical debt' it is probably not well written code, and thus arguing if well written code should be documented commented or not is irrelevant for that particular case.

---

I agree with a lot of the philosophy you don't like... I have been anti-comment and pro var for a long time.

I believe comments should not say what (names are for that) or how (instructions are for that)... yet, I think comments that explain why and for what are good. At the end the motivation for having less comments is that comments are not checked, and could be forgotten in refactoring, and thus there is a risk that they will be outdated... sure, we can argue dicipline, yet we use strictly typed languages for a reason. Thus, instead we want to express what we would have said in comments in code.

With that siad, I can tell you that using var as an extension of a no-comments philosophy is retrograde. The idea is to make the code express as much as it can (so it is explicit, that is what they mean by well written code, please do not confuse with verbose), so that we do not have things to communicate in comments... from that point of view, var is counterproductive.

Let us be clear, var is not dynamic typing. Yes, names can help with knowing the type※... yet, no, I am not advocating for hungarian notation either. So how can I be anti-comment and pro var if they are at odds?

I belive in the use of var as a way to protect the code from reasons to change. Same goes for auto. And yeah, I use it virtually everywhere. It eases refactoring (If I change the return type, using auto avoids a maintenance ripple of updating types everywhere the code is used), thus increases maintainability.

Addendum: You know what, I do realize it goes both ways, because if I did a poor job and returned something bad, auto will not complain. Although, I would expect it to break where we actually try to use the value.

If the code follows the robustness principle ("Be conservative in what you send, be liberal in what you accept"), we will not be using auto for the return type, instead the return type should be as specific as posible (without breaking encapsulation, if any). On the other hand, we want to assign the return value to a variable, and the return type is probably much more specific than you actually need in client code. In that situation we probably should not care of the particular type... in fact, we can argue that in that situation - if possible - it often makes sense to cast to an base class/interface that expresses what we need from the return type... and yes, you can use auto with a cast, yet, I will not be forcing you or anybody to use auto.

---

※: if I write auto highPriority = is_high_priority(w); the type of highPriority could be anything. However, it is expected that we can do if(highPriority){} or at least somebody did a very bad work at naming (somebody has been writing very bad code). Do not tell me that the names means nothing, names are for the people who read the code. If the name does not give you a clue and you need documentation to know what everything does, that is poorly written code. In fact, there could (and arguebly should) be naming convention that cover this. Yes, I understand that you want to see bool there, it gives people peace of mind. As I said above, I will not be forcing you or anybody to use auto.

So, nah, I'm not trying to convince you to use auto everywhere. I just wanted to give some insight on why one could advocate for zero comments and var everywhere. I felt misrepresented.
GeneralRe: Modern C++ auto Pin
dandy7225-Apr-19 9:42
memberdandy7225-Apr-19 9:42 
GeneralRe: Modern C++ auto Pin
GuyThiebaut23-Apr-19 6:44
professionalGuyThiebaut23-Apr-19 6:44 
GeneralRe: Modern C++ auto Pin
Maximilien23-Apr-19 7:14
memberMaximilien23-Apr-19 7:14 
GeneralRe: Modern C++ auto Pin
David O'Neil23-Apr-19 11:19
professionalDavid O'Neil23-Apr-19 11:19 
GeneralRe: Modern C++ auto Pin
Dean Roddey23-Apr-19 7:58
memberDean Roddey23-Apr-19 7:58 
GeneralRe: Modern C++ auto Pin
Dean Roddey23-Apr-19 15:50
memberDean Roddey23-Apr-19 15:50 
GeneralRe: Modern C++ auto Pin
Rage23-Apr-19 20:46
professionalRage23-Apr-19 20:46 
GeneralRe: Modern C++ auto Pin
Andy Hoffmeyer24-Apr-19 4:14
memberAndy Hoffmeyer24-Apr-19 4:14 
GeneralRe: Modern C++ auto Pin
wheelman570z24-Apr-19 7:11
professionalwheelman570z24-Apr-19 7:11 
GeneralRe: Modern C++ auto Pin
Andy Hoffmeyer24-Apr-19 7:41
memberAndy Hoffmeyer24-Apr-19 7:41 
GeneralRe: Modern C++ auto Pin
Dean Roddey24-Apr-19 7:55
memberDean Roddey24-Apr-19 7:55 
GeneralRe: Modern C++ auto Pin
Rick Shaub24-Apr-19 9:33
memberRick Shaub24-Apr-19 9:33 
GeneralRe: Modern C++ auto Pin
Dean Roddey24-Apr-19 10:00
memberDean Roddey24-Apr-19 10:00 
GeneralRe: Modern C++ auto Pin
Rick Shaub24-Apr-19 10:05
memberRick Shaub24-Apr-19 10:05 
GeneralRe: Modern C++ auto Pin
Dean Roddey24-Apr-19 10:19
memberDean Roddey24-Apr-19 10:19 
GeneralRe: Modern C++ auto Pin
Rick Shaub24-Apr-19 10:25
memberRick Shaub24-Apr-19 10:25 
GeneralRe: Modern C++ auto Pin
Dean Roddey24-Apr-19 10:45
memberDean Roddey24-Apr-19 10:45 

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.