C# Irritation
-
Simon Stevens wrote:
Adding const wouldn't actually change anything. The only benefit it would give is a compiler warning if you tried to change the value. But you shouldn't be changing the value anyway if you want it to be readonly.
Scenario: Method returns reference to internal object. This object represents a fundamental type in the domain of this particular app; there are hundreds of thousands of unique instances and they're used all over the place. At one point in its lifetime, it was mutable - special loader classes pulled data into it from many disparate sources, checking and double-checking, correcting and re-correcting. Therefore, it has public mutator methods. But at this point, it is to be considered immutable. C++: method would return a const reference. Any naive caller attempting to modify it would trigger a compiler error. C#: method must return interface rather than direct object reference, or rely on callers to Do The Right Thing, or set some dodgy "done changing state" flag internal to the object itself and implement const checking at runtime.
Citizen 20.1.01
'The question is,' said Humpty Dumpty, 'which is to be master - that's all.'
Shog9 wrote:
C++: method would return a const reference. Any naive caller attempting to modify it would trigger a compiler error.
Yes, and that naive caller (who's also foolish and stubborn) soon discovers that he can cast away constness and get away with murder. :-)
Shog9 wrote:
C#: method must return interface rather than direct object reference
This is the way I would do it (which the above guy can also cast away if he wants).
My latest C# extension method: public static bool In<T>(this T value, params T[] values) { return values.Any(v => v.Equals(value)); } Example: bool valid = answer.In("Yes", "No", "Dunno");
-
Daniel Grunwald wrote:
They're two different languages. Get over it.
Very good point, and succinctly put. C# has totally different design goals.
Simon
Simon Stevens wrote:
C# has totally different design goals.
I would phrase it that C# has totally different design constraints.
Anyone who thinks he has a better idea of what's good for people than people do is a swine. - P.J. O'Rourke
-
They still haven't produced a coordinate system where Y increases as you go up. This means that polar coordinates rotate the wrong way around the origin. How difficult can it be? They don't have X increasing to the left so why have Y increasing downwards? It's not difficult, other systems (e.g. RiscOS) have done it the right way up for years.
Because in user interfaces, the upper left corner is the origin. When you resize a screen, for example, you typically want the origin to remain where it is and have the bottom of the window reduce or expand.
Anyone who thinks he has a better idea of what's good for people than people do is a swine. - P.J. O'Rourke
-
Shog9 wrote:
C++: method would return a const reference. Any naive caller attempting to modify it would trigger a compiler error.
Yes, and that naive caller (who's also foolish and stubborn) soon discovers that he can cast away constness and get away with murder. :-)
Shog9 wrote:
C#: method must return interface rather than direct object reference
This is the way I would do it (which the above guy can also cast away if he wants).
My latest C# extension method: public static bool In<T>(this T value, params T[] values) { return values.Any(v => v.Equals(value)); } Example: bool valid = answer.In("Yes", "No", "Dunno");
Al Beback wrote:
Yes, and that naive caller (who's also foolish and stubborn) soon discovers that he can cast away constness and get away with murder.
Yeah, and i can still access anything i want to with Reflection in C#, or with direct memory access in C++. I can still write a COM method that does evil things with (in,out) parameters. So what? This isn't about security, it's about the ability to specify what's appropriate and have the compiler help you out if you forget what's what. You know. The same reason some of us use languages with explicit datatypes. When i want my language to act like Javascript, i use Javascript.
Al Beback wrote:
This is the way I would do it (which the above guy can also cast away if he wants).
You must work with evil, evil people... :~
Citizen 20.1.01
'The question is,' said Humpty Dumpty, 'which is to be master - that's all.'
-
Because in user interfaces, the upper left corner is the origin. When you resize a screen, for example, you typically want the origin to remain where it is and have the bottom of the window reduce or expand.
Anyone who thinks he has a better idea of what's good for people than people do is a swine. - P.J. O'Rourke
actually the convention is hardware derived. The electron beam in a CRT begins painting from the upper left.
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots. -- Robert Royall
-
True, sharing the pain is is always good.
Wout
Nah - This guys just whining.... Nothing better to do?
-
You need some anger management. :laugh:
Wout
10 out of 10 C++ programmers prefer unmanaged anger.
We are a big screwed up dysfunctional psychotic happy family - some more screwed up, others more happy, but everybody's psychotic joint venture definition of CP
blog: TDD - the Aha! | Linkify!| FoldWithUs! | sighist -
10 out of 10 C++ programmers prefer unmanaged anger.
We are a big screwed up dysfunctional psychotic happy family - some more screwed up, others more happy, but everybody's psychotic joint venture definition of CP
blog: TDD - the Aha! | Linkify!| FoldWithUs! | sighistYeah, the choice of words was an invitation for puns! :-D
Wout
-
Yeah, the choice of words was an invitation for puns! :-D
Wout
always happ to deliver :D
We are a big screwed up dysfunctional psychotic happy family - some more screwed up, others more happy, but everybody's psychotic joint venture definition of CP
blog: TDD - the Aha! | Linkify!| FoldWithUs! | sighist -
Al Beback wrote:
Yes, and that naive caller (who's also foolish and stubborn) soon discovers that he can cast away constness and get away with murder.
Yeah, and i can still access anything i want to with Reflection in C#, or with direct memory access in C++. I can still write a COM method that does evil things with (in,out) parameters. So what? This isn't about security, it's about the ability to specify what's appropriate and have the compiler help you out if you forget what's what. You know. The same reason some of us use languages with explicit datatypes. When i want my language to act like Javascript, i use Javascript.
Al Beback wrote:
This is the way I would do it (which the above guy can also cast away if he wants).
You must work with evil, evil people... :~
Citizen 20.1.01
'The question is,' said Humpty Dumpty, 'which is to be master - that's all.'
I was just making light of the fact that compilers can only go so far; it's really up to the developers to write proper code. Some languages help in some ways; others in other ways. I wish C++ enforced boolean expressions inside their conditional statements. :^)
Shog9 wrote:
You must work with evil, evil people...
Sometimes it's hard to tell.:-)
My latest C# extension method: public static bool In<T>(this T value, params T[] values) { return values.Any(v => v.Equals(value)); } Example: bool valid = answer.In("Yes", "No", "Dunno");
-
Because in user interfaces, the upper left corner is the origin. When you resize a screen, for example, you typically want the origin to remain where it is and have the bottom of the window reduce or expand.
Anyone who thinks he has a better idea of what's good for people than people do is a swine. - P.J. O'Rourke
Maybe so, but mathematical convention is for Y to increase going up, so as my main output in my Windows is graphical it's a PITA for GDI(+) to be upside-down! :) I think there should be a simple switch to turn it over, and another irritation, there should also be a simple way to grab the printer settings and set up a paginated display such as in Word.