It's not about how hard it is to substitute auto.
It's about how easy it can be made to figure out which auto to substitute.
Announcement
Collapse
No announcement yet.
John Carmack's Comments On C/C++
Collapse
X
-
Originally posted by plonoma View PostThe choice of the word auto as a keyword for automatically determining type is an abomination in terms of expressiveness.
The word autotype should have been used.
(Auto is just too short and ambiguous. People are going to make mistakes easier.)
Also in re factoring projects where the word auto had another meaning it's now more of a problem.
You have to define an alias to know what has been re factored and what not. (Must see the difference easily remember, can't use things that rely on keywords being different.)
And if you find it too hard to substitute auto, you might be using the wrong source code editor.
Leave a comment:
-
Originally posted by GreatEmerald View PostHow about this:
Code:writeln("Today is January ", 15, ", ", 2013);
Code:printf("Today is January %d, %d\n", 15, 2013);
Would like to do the following:
Code:uint intvariable = 5; setWrite(std::cout); writeln("sghsfmhj",12," tyjumdnjmjdsgjhpg ", 2013," pesriprtu", intvariable); write(" pegihjesj"); writeln(123); writeln({5}133);
Code:sghsfmhj12 tyjumdnjmjdsgjhpg 2013 pesriprtu5 pegihjesj123 133
Also being able to do toString();
With comma separated stuff like in the example.
Also being able to do a toStringNl();
Same as the previous function but with an endline behind it.
Being able to use the << operator here:
<<("sfsgfsf ", 45," sdrghjdsgol");
(also use of {} with multiple parameters, Example: {6,"^"} Would reserve six places and have as second parameter a filler for the empty space, also multiple {} on one, cascading to form more interesting outputs)
Short, easy readable, see what you get out of it, concise, very functional and high-level.
Leave a comment:
-
The choice of the word auto as a keyword for automatically determining type is an abomination in terms of expressiveness.
The word autotype should have been used.
(Auto is just too short and ambiguous. People are going to make mistakes easier.)
Also in re factoring projects where the word auto had another meaning it's now more of a problem.
You have to define an alias to know what has been re factored and what not. (Must see the difference easily remember, can't use things that rely on keywords being different.)
Leave a comment:
-
Originally posted by GreatEmerald View PostAnd for the reference, here's the D version (with an additional case and that is syntactically valid):
Code:template foo(T, O : int) { auto foo(T x, O y) { return x * y; } } int main() { string s = "text"; // 's' is text auto i = 0; // 'i' is an int auto f = 0.0 ; // 'f' is a double auto r = foo(s, i) ;// error: can't pass text as a first parameter auto r2 = foo(f, i) ;// works: because compiler can multiply a 'int' and a 'float' auto r3 = foo(i, i) ;// works: compiler can compile 'int' and 'int' auto r4 = foo(i, f) ;// error: can't pass non-int as second parameter return 0; }
Code:auto foo(T)(T x, int y) { return x * y; } void main() { auto s = "text"; // 's' is text auto i = 0; // 'i' is an int auto f = 0.0 ; // 'f' is a double auto r1 = foo(s, i); // error: can't pass text as a first parameter auto r2 = foo(f, i); // works: because compiler can multiply a 'int' and a 'float' auto r3 = foo(i, i); // works: compiler can compile 'int' and 'int' auto r4 = foo(i, f); // error: can't pass non-int as second parameter }
Leave a comment:
-
Originally posted by GreatEmerald View PostWell, even the very basic printing to console. C is consistent in that it uses a function for that, printf(). And C++ uses the "cout" notation that looks way out of place.
cout is actually an object and you just call operator "<<" on it. cout is not a keyword, it's just name for a struct that someone made and the "<<" operator was just simply chosen because it looks nicer than (+,-,*...). You don't have to use the STL library. It's absolutely not mandatory or recommended. (Embedded systems don't use STL, Qt doesn't use STL...)
Anyway, these operator overloading is a beautiful thing. You can do something like complexnum3 = complexnum1 + complexnum2 and you can define what + and = do. It's like automatic calling some function complexsum(c,a,b) without any overhead over ordinary function. The cout << is just like that. You can you use printf. You can write somehting new. You can even use inline assembly like in C.
Leave a comment:
-
Originally posted by GreatEmerald View PostThe first one was D, the second one was C.
Yea, it was an example that people picked up. In general I just feel that C++ is too reliant on all their operators, so code is no longer as easily readable if you are not familiar with the meaning of each.
Function overloading and the cascading behavior of operators make a strong case for this scheme ... no matter how unusual it looks.
In the end, most C++ programmers don't write their own operators (except for extending stream operators). Those that do are often doing it for mathematical objects (where it makes sense) or string-like objects (where + and "concatenate" are universally synonymous).
Leave a comment:
-
Originally posted by nslay View PostThe first one would never work in C. See stdarg.h for more information. In C++11, you can use variadic templates for a writeln() function as you described. But then, at the very worst, the compiler will produce a unique function for every output format you use. More likely, the compiler will inline such templated writeln() functions.
Originally posted by Ancurio View PostAlso, as to "printf() vs cout", that just seems like such a stupid and unnecessary discussion.
You're not discussing languages, only conventions of standard libraries at best.
Originally posted by h**2 View PostC++(11) does *exactly* this:
Code:template foo(T, O : int) { auto foo(T x, O y) { return x * y; } } int main() { string s = "text"; // 's' is text auto i = 0; // 'i' is an int auto f = 0.0 ; // 'f' is a double auto r = foo(s, i) ;// error: can't pass text as a first parameter auto r2 = foo(f, i) ;// works: because compiler can multiply a 'int' and a 'float' auto r3 = foo(i, i) ;// works: compiler can compile 'int' and 'int' auto r4 = foo(i, f) ;// error: can't pass non-int as second parameter return 0; }
Leave a comment:
-
Syntax being easy to read, expressive and flexible seems like it's the most important thing.
(I notice that with the << it's easier to read, produces smaller code and is (less error prone?) shorter than printf.)
(The use of the %s, %d specifiers has an issue since the type specification seems to conflict with the DRY principle of software engineering. )
Leave a comment:
Leave a comment: