Being Bit(ten) and Byting Back

Monday, April 25, 2005

musings on c#, c++, java and the meaning of __liff__ today...

Found out something interesting in C# the hard way :-|

You inherit a value type from an interface, and then attempt to cast an object to an interface, you will implicitly box it, and get a reference to it. Any changes to that boxed reference, will only affect that boxed reference. So the moral of the story is if your value types implement interfaces, then access those operations, through the object and not the interface.

The cool thing about learning something the hard way is that you always remember it afterwards, even though you have wasted a couple of hours on something trivial. :-)

One thing I like about C# is that you can pass parameters in different ways like C++. So value types are passed into methods by value,

ref parameters are used to pass value types into a method by reference and out parameters are used to only to return information from a method. Compared w/ Java, this is definitely an improvement. Actually you can achieve the same sort of effect with some indexer magic using the [ ] operator, but its kinda clunky. They could have avoided all of this by just making it like Like some functional language and returned everything as a tuple. After all, is'nt Python like Java or C#, utilizing a runtime to run its bytecode, like Java byte code, or MS IL?

Question to someone out there, what exactly is the difficulty in returning tuples from a method call in a OO language, a'la Python, Lisp, or Haskell?

In a way I think, all languages are gradually getting there. C# already has features like foreach and params, which is akin to Python's argument passing scheme, (when declaring a method like def foo(**args), and that passes a dictionary of arguments). C++ already can do this sort of thing using generic programming. So can you pass in different parameter lists of objects using the params and object keywords in C#, something like

void foo(params object[]bars){ .... } ?

And the answer to the above is that you can !!

One of the stuff I need to do for some work related stuff is to experiment with some Managed Extensions for C++. At work, I'm working with a lot of legacy code, that needs to be somehow integrated as we migrate to newer technologies.

Not Much on the Meaning of __Liff__ today.. May be tomorrow. Too bad this font is going to be appear only on computers, that have it installed, I don't see it on my Windows XP box. It looks really nice on my Mac.

0 Comments:

Post a Comment

<< Home