Author Topic: A C# Event Primer (for iago!)  (Read 21475 times)

0 Members and 2 Guests are viewing this topic.

Offline MyndFyre

  • Boticulator Extraordinaire
  • x86
  • Hero Member
  • *****
  • Posts: 4540
  • The wait is over.
    • View Profile
    • JinxBot :: the evolution in boticulation
Re: A C# Event Primer (for iago!)
« Reply #45 on: November 09, 2007, 04:51:32 pm »
Either way, I think I make a good point. :P

So did Hitler.  :P
I have a programming folder, and I have nothing of value there

Running with Code has a new home!

Our species really annoys me.

Offline iago

  • Leader
  • Administrator
  • Hero Member
  • *****
  • Posts: 17914
  • Fnord.
    • View Profile
    • SkullSecurity
Re: A C# Event Primer (for iago!)
« Reply #46 on: November 09, 2007, 05:00:58 pm »
Either way, I think I make a good point. :P

So did Hitler.  :P

If Hitler was alive, he'd probably like C#. So you must be wrong.

Offline Blaze

  • x86
  • Hero Member
  • *****
  • Posts: 7136
  • Canadian
    • View Profile
    • Maide
Re: A C# Event Primer (for iago!)
« Reply #47 on: November 09, 2007, 05:12:21 pm »
Either way, I think I make a good point. :P

So did Hitler.  :P

If Hitler was alive, he'd probably like C#. So you must be wrong.

Obviously!  Also, Stalin would still be boasting about how QBasic is the best.
And like a fool I believed myself, and thought I was somebody else...

Offline iago

  • Leader
  • Administrator
  • Hero Member
  • *****
  • Posts: 17914
  • Fnord.
    • View Profile
    • SkullSecurity
Re: A C# Event Primer (for iago!)
« Reply #48 on: November 09, 2007, 06:49:14 pm »
Incidentally, shame on Myndy for invoking Godin's Law! :)

Offline MyndFyre

  • Boticulator Extraordinaire
  • x86
  • Hero Member
  • *****
  • Posts: 4540
  • The wait is over.
    • View Profile
    • JinxBot :: the evolution in boticulation
Re: A C# Event Primer (for iago!)
« Reply #49 on: November 09, 2007, 07:27:43 pm »
Incidentally, shame on Myndy for invoking Godin's Law! :)

Hahahahahahaha.  <3!
I have a programming folder, and I have nothing of value there

Running with Code has a new home!

Our species really annoys me.

Offline Camel

  • Hero Member
  • *****
  • Posts: 1703
    • View Profile
    • BNU Bot
Re: A C# Event Primer (for iago!)
« Reply #50 on: November 10, 2007, 11:24:53 am »
structs in general feel like a hack. :)
Only because they do something useful that Java doesn't. :P

The reason I structs seem hacky to me is that they are subclasses of Objects, but their behavior is completely different. You can't even do that in C#, which definitely makes it a framework hack.

<Camel> i said what what
<Blaze> in the butt
<Camel> you want to do it in my butt?
<Blaze> in my butt
<Camel> let's do it in the butt
<Blaze> Okay!

Offline Joe

  • B&
  • Moderator
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Re: A C# Event Primer (for iago!)
« Reply #51 on: November 10, 2007, 04:18:03 pm »
structs in general feel like a hack. :)
Only because they do something useful that Java doesn't. :P
You just said they're useless!

The difference between .. C# and .. Java: [C#] is faster. .. Big deal!
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline MyndFyre

  • Boticulator Extraordinaire
  • x86
  • Hero Member
  • *****
  • Posts: 4540
  • The wait is over.
    • View Profile
    • JinxBot :: the evolution in boticulation
Re: A C# Event Primer (for iago!)
« Reply #52 on: November 10, 2007, 05:41:25 pm »
The reason I structs seem hacky to me is that they are subclasses of Objects, but their behavior is completely different. You can't even do that in C#, which definitely makes it a framework hack.
Wait, what?  I just described how you do it in C#....  You declare it as a "struct" instead of a "class."
Quote from: C# Language Reference section 1.3
C#’s type system is unified such that a value of any type can be treated as an object. Every type in C# directly or indirectly derives from the object class type, and object is the ultimate base class of all types.

.....

However, unlike classes, structs are value types and do not require heap allocation. Struct types do not support user-specified inheritance, and all struct types implicitly inherit from type object.
I have a programming folder, and I have nothing of value there

Running with Code has a new home!

Our species really annoys me.

Offline Camel

  • Hero Member
  • *****
  • Posts: 1703
    • View Profile
    • BNU Bot
Re: A C# Event Primer (for iago!)
« Reply #53 on: November 11, 2007, 05:01:41 pm »
Structs are classes, but instances of structs do not behave the same as instances of classes. How is that not hacky? Behavior is supposed to be inherited, not arbitrarily redefined.

<Camel> i said what what
<Blaze> in the butt
<Camel> you want to do it in my butt?
<Blaze> in my butt
<Camel> let's do it in the butt
<Blaze> Okay!

Offline MyndFyre

  • Boticulator Extraordinaire
  • x86
  • Hero Member
  • *****
  • Posts: 4540
  • The wait is over.
    • View Profile
    • JinxBot :: the evolution in boticulation
Re: A C# Event Primer (for iago!)
« Reply #54 on: November 11, 2007, 08:03:48 pm »
Structs are classes, but instances of structs do not behave the same as instances of classes. How is that not hacky? Behavior is supposed to be inherited, not arbitrarily redefined.
It's not "arbitrarily" redefined - it's formally defined.  See: the C# language reference.

That's like saying that floats are numbers, and integers are numbers, but they do not behave the same.
I have a programming folder, and I have nothing of value there

Running with Code has a new home!

Our species really annoys me.

Offline iago

  • Leader
  • Administrator
  • Hero Member
  • *****
  • Posts: 17914
  • Fnord.
    • View Profile
    • SkullSecurity
Re: A C# Event Primer (for iago!)
« Reply #55 on: November 11, 2007, 08:48:41 pm »
Structs are classes, but instances of structs do not behave the same as instances of classes. How is that not hacky? Behavior is supposed to be inherited, not arbitrarily redefined.
It's not "arbitrarily" redefined - it's formally defined.  See: the C# language reference.

That's like saying that floats are numbers, and integers are numbers, but they do not behave the same.
It's formally defined, but, as much as it hurts to agree with Camel, I think it feels like a hack. floats and integers behave the same way (or, at least, consistently) when you perform the same operations on them, which isn't something that can be said for structs (in my opinion).

Offline MyndFyre

  • Boticulator Extraordinaire
  • x86
  • Hero Member
  • *****
  • Posts: 4540
  • The wait is over.
    • View Profile
    • JinxBot :: the evolution in boticulation
Re: A C# Event Primer (for iago!)
« Reply #56 on: November 11, 2007, 08:57:34 pm »
So, int can behave both ways in Java too, right?  So it's a hack too?

Or how about the way that autoboxing was hacked into the Java compiler but doesn't have intrinsic support in the runtime?
I have a programming folder, and I have nothing of value there

Running with Code has a new home!

Our species really annoys me.

Offline iago

  • Leader
  • Administrator
  • Hero Member
  • *****
  • Posts: 17914
  • Fnord.
    • View Profile
    • SkullSecurity
Re: A C# Event Primer (for iago!)
« Reply #57 on: November 11, 2007, 09:32:48 pm »
I don't believe that int can behave both ways. The base type (int) behaves like a base type, and the class (Integer) behaves another way. There are things in Java that feel hackish, but that's not one of them.

I have no idea what autoboxing is. I don't have a whole lot of formal training in languages except for C, so I don't know the terms for a lot of things.

Offline Camel

  • Hero Member
  • *****
  • Posts: 1703
    • View Profile
    • BNU Bot
Re: A C# Event Primer (for iago!)
« Reply #58 on: November 12, 2007, 01:02:32 am »
When did agreeing with me become inherently tabu?

In Java, ints do not behave both ways. Ints are base types, and are passed, as all base types are, by value. Integers are Objects, and are passed, as all Objects are, by pointer-value. There are no Java Objects that revert to being passed as the sum of their fields (with the exception of uboxed numbers, which doesn't count).

Autoboxing is the silent up-conversion of a base type to an Object. Ex:
Code: [Select]
Integer i = (int)2;
Java also has automatic unboxing:
Code: [Select]
int i = new Integer(2);
If you switch down to a Java 1.4 compiler, and try to compile the following:
Code: [Select]
Integer x = new Integer(1);
Integer y = new Integer(2);
Integer z = x + y;

You will get an error indicating that two Objects can not be added together. In Java 5, this was solved by adding autoboxing/unboxing; the third line will unbox the Integers to ints, add them, and autobox them back in to an Integer.

It isn't hacky because it's intuitive, and it isn't in the runtime for two reasons: one, for backwards compatibility. Two, you can't overload operators in Java. As we've already discussed, Java doesn't believe in operator overloading, with the exception of number objects (because they're being used to do math on numbers which is intuitive) and java.lang.Strings (because typing out .concat is tedious and is less intuitive than using +). There simply aren't any other conditions where the + operator, or any operator for that matter, can be used intuitively.

C# structs are hacky because they aren't intuitive, and because they don't inherit behavior from their parent class, System.Object.



If you really are going to insist that autoboxing is hacky, you should also complain about the automatic import of java.lang.*, because it's equally as hacky, and less intuitive.
« Last Edit: November 12, 2007, 01:06:57 am by Camel »

<Camel> i said what what
<Blaze> in the butt
<Camel> you want to do it in my butt?
<Blaze> in my butt
<Camel> let's do it in the butt
<Blaze> Okay!

Offline MyndFyre

  • Boticulator Extraordinaire
  • x86
  • Hero Member
  • *****
  • Posts: 4540
  • The wait is over.
    • View Profile
    • JinxBot :: the evolution in boticulation
Re: A C# Event Primer (for iago!)
« Reply #59 on: November 12, 2007, 04:50:26 am »
C# structs are hacky because they aren't intuitive, and because they don't inherit behavior from their parent class, System.Object.
Do you understand what "behavior" means in an object-orientation sense?

Behavior in OO land is the type of behaviors an object exhibits to the outside world - ways to change state.  Whether an object lives on the heap or the stack is not part of OO, nor is whether an object is copied by value or reference - it's entirely a semantic part of the language.  The fact that a language enables you to define it indicates that it's rather expressive, instead of hackish, don't you think?

I have a programming folder, and I have nothing of value there

Running with Code has a new home!

Our species really annoys me.