András
So, are all your functions named thisFunctionReturnsDouble()? I'd like to see your code :p
No, all my names are like get_time() dfs() bfs() dejkstr(), ...
Artöm
If v is double and you change the function to something that returns int, v becomes int. And somewhere else, where you where doing other_var=v/33;, you get something different of what you expect. But no errors.
Lets return to this example. If you have reasons to assume this function returns integer, I dont understand why it can be changed to double. If not, you should have performed explicit cast yourself
Artöm
Or give another example. I believe auto smells in certain places
Javi
Why did you have var = v / 33; here, but not var = v / 33.0; if like so much too take precisions? Why don't you write var = double(v) / 33.0;
Do you really suggest double var=(double)v/33.0? Why do I have that? Because it is an example, and sometimes we work on somebody else's code. And if you find every variable defined as auto, it is a nightmare to find out what is what
Artöm
I never write auto for ints or doubles or simple structs because thsts dumb and useless
András
There is no memory leak and the program works. But not as expected
I am talking about the same situation, but in a little bit different situation
Pavel
Lets return to this example. If you have reasons to assume this function returns integer, I dont understand why it can be changed to double. If not, you should have performed explicit cast yourself
How it's for me: I have warnings for implicit types casts (yes, I cast everything, even int to double with static_cast myself). There are lots of overloaded and templated functions that take different types (e.g. min(T a, T b) or to_string(T). If I'll put auto everywhere, I can get lot of places where it can change some logic if I accidentally change type somewhere
Javi
Lets return to this example. If you have reasons to assume this function returns integer, I dont understand why it can be changed to double. If not, you should have performed explicit cast yourself
auto t=myTime(); I'm returning a time. In what format? Integer number of seconds, float number of seconds, a struct? auto t=myTimeInSeconds(); Is it an int or a float, or a double? Or did the programmer created a mySeconds class?
Javi
God, who said its better to use auto in this oarticular case?
You are asking me for examples. This is one. Obviously I can't give you all and every case where auto leads to problems
Artöm
And I said its better not to use auto here
Javi
Or following @Pavel's example. If you have template specialization, suddenly you may end up using a completely different template
Pavel
I have warns for sign mismatch and use braces
How it will help for example when I change a function to return double instead of int and then call some overload function that can take both with the result?
Javi
Again, I don't say "never use auto", but in most cases, I don't think the risks compensate the usually small advantages
Artöm
Or change signedness
András
You are asking me for examples. This is one. Obviously I can't give you all and every case where auto leads to problems
Oh, you asked me, which name I use for a function. Right now, I am working with function shared_ptr<fucking_rabbit_very_fast_random_move_class> next_step()
Javi
Which function can suddenly return int instead of double?
I gave you one example. You have a function that returns a number of seconds (or minutes, or hours). At first it's fine that it returns an int, and then you realize it should be a double
Javi
Or meters, or any kind of measurement
Anonymous
Javi
Which is mostly bad architecture
So template specialization is bad architecture...
Javi
Like overloading
András
Cool. I have no idea what methods fucking_rabbit have, and what do they return
Emm, function name is next_step(), and return type is shared_ptr<fucking_rabbit_very_fast_random_move_class>
Artöm
So template specialization is bad architecture...
Template specialization which changes api in hard way
Artöm
Like vector bool
Pavel
Which is mostly bad architecture
Maybe bad, but it's everywhere. Even using just STL and some popular parsers we can get some problems like that.
Javi
And months later you refactor it to be a unique_ptr
Javi
Can you see any possible trouble?
Pavel
I can name lots of good specislizations in std and couple of nasty ones
I just want to say, it doesn't matter if it's good or bad if it exists and you can't avoid it
Artöm
I dont need to. Most specializations work well with auto. Some dont
Javi
I dont need to. Most specializations work well with auto. Some dont
Ok, if you work in an environment where all the code is 100% tested and all the programmers are geniuses, I envy you
András
Well, so now, several thousands lines away, you have auto v=next_step();
Yeah, and? Firstly, I make my code more readeble, becouse, I don't need to write 150 symblos, just to initialize some variable, secondly, I write code faster, becouse I don't make misstake in naming, so IDE can autocomplete my code, and so on and son on
Artöm
Via using. Maybe in same block
András
Artöm
Wut
Pavel
typedef makes code unreadeble
Disagree, you can name things by intentions. Not int but MyType::IndexType
Javi
Francisco
typedef makes code unreadeble
You should use using for type aliases, not typedef
Javi
And all the fast that you write your code, is undone trying to figure out what went wrong
Artöm
How often do yall change return type?
Francisco
They are equivalent
No, they aren't
András
So, lets typedef long long ll; And that, who try to understand what you've wrote will confuse
Javi
No, they aren't
The only difference is if you use templates
Pavel
No, they aren't
using supports template parameters and looks better, but are there other differences?
András
I definitely didnt mean this usage
So in which case typedef is better, than good naming?
Artöm
typedef int(*signal)(stuff_t, void*); vs using signal = int(*)(stuff_t, void*);
Artöm
So in which case typedef is better, than good naming?
When naming is 30+ symbols long because of namespaces and templates
Artöm
You can name it better in this particular piece of code
Gladiator
Please someone should help me understand .... Loops ,data types ,arrays and pointers
Gladiator
I will be very glad
Pavel
Isn't it enough differences?
Enough for me, I just thought you meant something else
Artöm
Read a book
Gladiator
Read a book
Please which book?
András
Read a book
Or at least some tutorials
Artöm
Please which book?
Stephen Prata
Gladiator
Stephen Prata
For c++ tutorials?
Artöm
Or C. He has couple of books
Gladiator
Okay
Javi
with namespaces it is about 67 symbols, so I use auto
I would use ctrl+c, ctrl+v and if you change the return type to unique_ptr and forgot about it, you get a compile error, instead of a runtime error
Javi
Or using at the beginning of the method that uses it
András
I would use ctrl+c, ctrl+v and if you change the return type to unique_ptr and forgot about it, you get a compile error, instead of a runtime error
cntr+c, cntr+v from where? So I need to navigate to file, where I created a class, paste it 3 times, make 200 symbols line, just becouse I don't want to use auto. It is stupid
Javi
cntr+c, cntr+v from where? So I need to navigate to file, where I created a class, paste it 3 times, make 200 symbols line, just becouse I don't want to use auto. It is stupid
You have to navigate the same to find out what auto means. The difference is that with copy-paste, you do it once. With auto, every time you revisit the code
Javi
It can make code less readable
The naming is making it less readable, auto doesn't improve that
Javi
At least, just by looking at the definition you know you are dealing with a shared pointer
Artöm
Btw sometimes type is irrelevant auto coll = get_collection; for (const auto& e : coll) { stuff(e); }