Re:Java Was Strongly Influenced by Objective-C
by AnimalMuppet on Thursday June 25, 2015 @04:01PM
(#9780554)
I keep seeing that "strong types" comment here. In what sense are Java types "strong" and C++ types "weak"?
[ Parent
| on HN ]
Re:Java Was Strongly Influenced by Objective-C
by ajuc on Thursday June 25, 2015 @05:34PM
(#9781054)
For one example:
float a = 1.0; // compilation error in java, no problem in C++
For another: int a[5] = { 0, -1, 2, 3, 4 };
(1+a) = 1; // :)
Also: assert( !(1/2) );
Also: enum Foo {A, B};
enum Bar {C, D};
Foo e1 = A;
Bar e2 = C;
int i = 0;
assert(e1 == e2); // warning
assert(e1 == i); //no problem whatsoever
Re:Java Was Strongly Influenced by Objective-C
by AnimalMuppet on Thursday June 25, 2015 @05:50PM
(#9781136)
I'd argue that in the case of your first example, C++ is correct. Promoting int to double in this case does not bother me whatsoever. (In fact, mathematically, an integer is a real, though the reverse is not always true.
I will concede that the others are problematic...
Re:Java Was Strongly Influenced by Objective-C
by ajuc on Thursday June 25, 2015 @06:28PM
(#9781311)
In 1 the problem is silently discarding double precision to float precision. I edited the example to be less confusing.
Re:Java Was Strongly Influenced by Objective-C
by AnimalMuppet on Thursday June 25, 2015 @06:37PM
(#9781352)
Ah. Yes, I was confused; I thought the issue was the promotion of the 2 from int to floating point.
Also I made an error - should have been
*(1+a) = 1;
Still bad but not as bad.
Re:Java Was Strongly Influenced by Objective-C
by AnimalMuppet on Friday June 26, 2015 @03:21PM
(#9787113)
After thinking about it a bit, that also is well-typed in C. (You can argue that it shouldn't be allowed, but that's a different argument than that the language is not strongly-typed because of that feature.)
Re:Java Was Strongly Influenced by Objective-C
by AnimalMuppet on Friday June 26, 2015 @11:50AM
(#9785410)
Or:
1[a] = 1;