2008-06-14

var in C#

So this looks like yet another flame-provoking topic. Use var or not? Many say this is matter of taste, and that this is analogous to weak typing vs strong typing - both exist successfully.

var i = short.MaxValue;
i++;

Oh well, nobody uses other integer types beside int today anyway. Similar to var, eh? "I don't care what are limits for this type, all that i am interested is that it contains integers". In case of int, i agree, this is most often the best choice, it eliminates the need of typecasting on arithmetic oparations with different types, and few (k)bytes spared are probably not worth headaches choosing between "short" and "int". The similarity is that both reduce the need of thinking.
Matters with var are a bit different. In fact, it does not change semantics of the program, it just makes it a little bit less verbose, ie eliminate some "syntactic noise". So for me this is all about how much redundancy do we need in our code? If there is too much, the code is bloated and it is difficult to find what you need. If, on the other hand, there is too little, it can be hard to understand intent of the code. Talking about verbosity, i always remember code contracts. For me, code contracts look like very nice idea, and although i have never used them, i feel they will appeal to me much more than unit tests, when i have a chance to use them.
Personally, i never use var when not necessary(with anonymous types). Who says it saves typing? Gee, are you programming in notepad or what? In VS IDE, you write first three letters of type name and hit space, 80% you have the right type... Only thing i can imagine you save here is code size, and that's why i will probably use var in my homemade 100-loc programs. For some reason i just feel offended when i see peer programmers writing something like

var client = order.Client;

But again, i feel this is just something you have to get used to. I feel i may change with time, and will be eagerly using this feature everywhere i can, until i start abusing it, which will cause other problems, until i settle on a golden middle, or well, be forced there by some coding standard rules. On a side note, similar feature is proposed for C++0x (auto), a language i have deep trust in.

2008-06-08

book review: Larry Niven - The Ringworld Engineers

This is the book i've recently read, translated into my native language - lithuanian, of course. This is the sequel to the Ringworld novel, which won both Hugo and Nebula awards. There are further sequels also. So having not read original Ringworld, i still thought The Ringworld Engineers will still be a good reading.
Why haven't i read original novel? Well, because in SF i read what is at hand, what is on a bookshelf in local bookstore, basically not worrying too much whether i am wasting my time. And so often it happens that what others rate high does not impress me and vice versa - so better read random book, and maybe i will discover something wonderful, without apriori judgement. In contrast, regarding professional books (in software engineering, etc), i always choose to read recognized one - maybe because i got sick after reading some books by authors who had no idea what they were writing about, just transcribing what they have read in some manual. I am not kidding, i've seen quite a lot of that kind.
If fact this book was quite a pleasure to read, but still, i thought, could have been better. Nothing to compare to eg Frank Herbert's Dune. I would rate it 4/5. Another thing that bothered me a bit is that there were notably too many grammar errors. My guess is translators were pressed too hard :/
Ringworld is artificial construction - flat ring rotating around the sun in the centre. Its rotation induces gravity-alike force on the inner surface of the circle. All environmental factors are similar to Earth's, and so various hominid species live there. The main point of the novel is that ringworld by itself is not stable - it will eventually collide with the sun. To solve this problem, there were lots of Bussard ramjets on the edge of ringworld, which collect hydrogen from surrounding space as fuel, and can compensate for ringworld's random shifting, 95% of which are now unfortunately gone, and remaining ones are not enough to stabilize ringworld's orbit already. And here our adventure begins - our heroes have to find a way to stabilize ringworld. And that's why i rated this 4/5 - because those adventures, well, could have been more interesting. Regarding ideas - this book is perfect for me. Now our hero is like drug-addict, he stimulates his brain pleasure centre with electric current(another nice idea), and well, seems a little bit detached from the world. Well i dunno, maybe this is because i've read R.C. Wilson's Spin, which was masterpiece in that regard - character's inner universe.
So, my collection of interesting topics from this book (which i will hopefully have a chance to speculate about with my bro, who happens to study physics):
  • General ringworld physics - why is it unstable, etc
  • Bussard ramjet
  • Human evolution, evolution speed
  • Stimulating brain pleasure centers with electric current
  • Solar flare manipulation via magnetic field, solar flare fo laser
  • Superconductors, their usability
  • Impact armor, which hardens on impact to protect the wearer

VB, C#

Recently at workplace i heard our projects manager muttering something like "THEY ARE USING VB?? gosh, they must be total newbies", and eveyone around nodding in approval; well not exactly the same wording, but thats what i heard between the lines. So whats wrong with VB?
I myself grew in environment where VB was like "american thing", "not for real programmers", etc. And so probably that is the reason i never really tried it - well, except macros in VS. But still there is one thing i believe - having seen many opinions, and also from my own experience - c# is quite similar to VB. Haven't you heard developers migrating from VB to C#, and not that many complaints - this must say something. Needless to say, here write programs in C#, and well, i guess almost everyone here thinks it is the coolest language in the world. Of course, we can extend this further and say all OO languages are so similar -and of couse they have many similarities. IMO, VB and C# aren't so drastically different to make one "cool", and the other "ugly". If you dont't like VB keywords, this is exactly if you wouldn't like those C-style {}. I think this is not enough a difference, and i haven't heard any fundamental ones - all just a matter of taste.
And to think of it, is C++/CLI that different from C#? For me it looks like old good standard C++ plus subset of C# with different keywords. They all depend on same CLR, which i guess was designed mostly having one language in mind - C#. I think this has some implications on language, which is to target CLR, despite of what they say how CLR is so flexible and can support any language. If not for anything else, then for interop between .NET languages.

why this blog?

It so often happens to me that i say something and noone seems to understand :). Well, this applies to my field of expertise - software engineering. Like, i say "OK, this is possible, but..." - and nobody seems to care that there is "but" and something after it. Of course, this is just standard human reaction, to dismiss what you cannot comprehend, but still i feel very often it would have been better if those words were heard, also considering that i usually talk only when i think i have something important to say(things like "oh, you must have been to a barber, what a nice haircut!" are not considered important by me despite of possibly having emotional impact which could very well cause some important things to happen - bun anyway, who is to measure that?). So, for not to feel uneasy for letting my words in vain, i will write something here.
Also, i read quite a bit science fiction, fantasy books, mostly in my native language - lithuanian, and sometimes in russian. And of course i read books in programming - ranging from algorithms/complexity to software projects management. So i will try to post impressions on my readings here as well.