Jonathan M Davis

less info
1,384 reputation
69
bio website github.com/jmdavis
location Fresno, CA
age 32
visits member for 3 years, 8 months
seen Jan 14 at 23:04

Dec
20
comment Can modern OO languages compete with C++'s array store performance?
@supercat If you want to write a function which sorts arbitrary types, then templatize it. e.g. dlang.org/phobos/std_algorithm.html#sort
Jan
17
comment Can modern OO languages compete with C++'s array store performance?
@BenVoigt Then the online docs need to be updated. They aren't always 100% up-to-date unfortunately. The conversion will work with const U[], since then you can't assign the wrong type to the array's elements, but T[] definitely does not convert to U[] as long as U[] is mutable. Allowing covariant arrays like it did before was a serious design flaw which has now been corrected.
Jan
17
comment Can modern OO languages compete with C++'s array store performance?
@Jesse And when else would you expect exceptions but at runtime? The problem isn't code which throws exceptions at runtime - there are plenty of cases where that makes good sense - the problem is code which is guaranteed to be wrong which doesn't get statically caught by the compiler but instead results in an exception at runtime.
Sep
14
comment Why is the 'final' keyword used so little in the industry?
Yes, it's a common design, but OO programming isn't necessarily looking to have everything in an object be mutable. OO programming deals with how you organize your code not necessarily whether any of it's mutable or not. Data is organized into objects which have functions on them which then operate on the data as one entity. The internals of that object are then encapsulated and aren't generally relevant to those using it. Much of the time, variables are mutable (and in Java, final is crippled enough that it doesn't add much anyway), but OO does not strive or require that they be mutable.
Aug
4
comment What does C++ do better than D?
Well, aside from whether C++ references can ever be null, the current answer looks correct.
Aug
2
comment What does C++ do better than D?
So yes, being able to have a class reference which is non-nullabe would be nice, but C++ manages to do what you're showing because it allows for classes to be on the stack and allows for pointers to be dereferenced. And while you can dereference pointers in D, classes are references, not pointers, so you can't dereference them. Since you can't put them on the stack, and you can't dereference them, there is no way built into D to have a class which can't be null. It is a loss, but NonNullable will fix it, and the gains from the separation of structs and classes are generally greater anyway.
Aug
2
comment What does C++ do better than D?
You're confusing things. Classes are always references, and that's separate from ref. References in D are like references in Java. They're managed pointers. Passing or returning by ref is like passing or returning with & in C++. Passing a class reference by ref is like passing a pointer in C++ with & (e.g. A*&). Classes don't go on the stack. Yes, NonNullable would make it possible to have a class reference which was guaranteed to be non-null, but that's completely separate from ref. What you're trying to do in the C++ code doesn't work in D because classes don't go on the stack. Structs do.
Aug
1
comment What does C++ do better than D?
Both function arguments and return values in D can be marked with ref to give you the same effect as C++'s &. The one major difference is that ref won't take a temporary even if it's const.
Dec
2
comment System Programming & Object Oriented Design - what to look out for
It's pretty much the original book on C, and it's definitely classic, so it would be a good one, but I do think that it's outdated in some respects, so while it's good, that's something to be aware of. The advantages of a book targetting Java programmers in particular (if you can find one) is that it'll be able to point out the places where you're likely to run into trouble. But that's not a requirement by any means. It would just be useful.