Home > Rant > Visual Studio and C# Impressions

Visual Studio and C# Impressions

Disclaimer: Only programmers will be able to appreciate this entry. And even that’s not certain.

I wrote a much longer entry yesterday but after some thought I realized that nobody would read it, and there was no point to share all that, because pure C# programmers wouldn’t learn anything new and pure C++ programmers wouldn’t get it.

Last year just before Christmas I installed the free Visual Studio 2010 Express on my machine, namely its C# and C++ compilers. I was curious about VS, as I haven’t seen it for some time and never tried C# before. I can confirm that it’s very easy to start with that language (at least if someone has 12 years experience with C++), because I finished my very first Windows forms application with it,ย a simple clone of minesweeper, with dynamically created cells and all, in one and a half hours after first starting up VS, without knowing anything about C#. (This time includes reading documentation and hunting for information online, the actual writing didn’t take longer than half an hour at most.)

Of course this didn’t make me an experienced C# programmer, and I didn’t spend enough time getting used to the IDE of VS either. VS has some glitches that became apparent from a littleย  use though. For example compiling in the C# IDE is invoked with the F6 key, while in the C++ IDE it’s F7. I would expect the same keys to execute the same basic functionality in both interfaces. It is a single company after all. The other glitch was with the compiler paths. I can’t remember whether I have changed the install path for the compilers, but the C++ IDE couldn’t find the compiler’s “Cl.exe”. I found nothing about it after searching online, but then checked the compiler macros, namely the macros used for the program paths, and noticed an error in one of them. There was no way to change that path from the program itself, but fortunately the paths are not encoded, and a little work with regedit helped me find and correct the error. (Yep, MS still hasn’t learned not to hard code paths in its programs or installers.)

Every program has bugs, and I haven’t spent enough time with VS to discover more, so I’ll leave it at that. The only thing I could do in such a short time was to compare some features of VS with the ones in Rad Studio that I’m using to write zkanji. The form designer of VS is an obvious rip off of Rad Studio’s (or rather the original in Delphi from 1995), which is not a problem in itself, though I found the designer in VS a bit unresponsive and slow when moving controls around a form. I found some inconveniences as well that work so nicely in Rad Studio but not in Visual Studio for some reason. The most obvious is how some controls can only be moved in VS by grabbing a small icon at the top border of a control. I might be a bit unfair here as I’m used to RS too much, but its solutions feel much better to use.

On the other hand the text editor part of VS is light years ahead of the one in RS. It’s faster, and the IntelliSense, which helps writing the code works much better than the CodeInsight of RS. They both suggest possible names for variables and their functions, the functions’ arguments etc. but VS makes it look like it’s easy, while RS is clearly struggling each time. (This may be due to the huge code of zkanji, but I can’t be sure until I have written something just as big in VS.) The way how VS completes code and formats the lines, so brackets always start at a new line and all those little things are done much better than in RS as well.

Up till now was my impression about Visual Studio, so let me write about C# and .NET as well. I have 12 years of C++ experience, so I can’t help but to compare the two languages. It’s clear, that C# was derived from C++, because they share many keywords and the way loops for example work is very similar as well. Of course C# has foreach and an sql like expression to collect items from lists and arrays, and C++ only gained some of the functionality with C++11 (and we have to see until every compiler starts to support it.) If someone knows how to use C++, C# won’t be difficult at all. Starting with it is just a matter of minutes, not even hours. They usually say that this is one of the strong points of the C# language (I heard something similar about Java a decade ago). In my opinion this is not necessarily a good thing, but not bad in itself either. After spending days reading the C# language reference I think that it is a language that looks simple, and it is easy to start with some simple programs, but using something that has simple rules can get very complicated with time.

I never liked garbage collection so I’m prejudiced, and because of that I’d rather not get into this part of the language, just mention what I think about languages with no pointers in general. When we start hiding pointers the language loses features. Even in C++ you could write and use classes that hide the pointers, and it is probably better for safety as well, but at least they don’t take away the tools. This doesn’t have much to do with C# so I stop here. I’d rather write about my first impressions, if that was the title of this entry.

As I was writing, it’s true that C# seems much easier to learn than C++. The biggest headache I had in C# was with class inheritance and mainly virtual functions and properties. I find it odd and a bad design that you can’t change the visibility of C# class members. Why is that, that when a virtual property was declared protected in a base class, it can’t be made public in a derived class? Or what is even more problematic, if it was public, it can’t be made protected? I found an answer on a site where someone asked the same question. One of the first people to answer said that it would be against the principles of Object Oriented Programming, though I have never heard of such principle. If you know about it, please tell.

Imagine the situation that you create a new listview control, that can only show its items as rows in a detailed list. (Listview is the control that lists files in the right part of Explorer. It can show the files as icons, or it can show details etc.) In C# it is impossible to change the visibility of the public virtual “View” property to protected. With a little research I found the solution, hiding the property with a new one with the same name, that only has a public getter function, while the setter is either private or doesn’t exist. It is strange though that such thing is not directly supported by the language, and you have to use tricks. This seems to be a much worse alternative.

In the short time I tried C#, this was the only real problem I had with it. It’s a true programming language. I don’t know if it is good or bad because I really haven’t used it enough, but against all my prejudice, it seems to be quite usable. I think there are some design flaws in .NET, and it would be difficult to separate C# from .NET, but unless I used it much more, I’d rather not comment on that aspect of the language. Also MS seems to be in love with interfaces which clearly appear in C#, and that in my opinion is an unnecessary solution to a problem that doesn’t exist, but it has little to do with this blog post.

I would like to create a “solution” (as projects are called in VS), that requires me to dig deeper into the depths of both the language and .NET, but I can’t think of anything right now that would be worth it. Suggestions are welcome ๐Ÿ˜‰

Categories: Rant Tags: , ,
  1. Funbit
    January 12, 2012 at 7:25 am

    Oh man, a couple of months with C# is truly not enough to realize how well the platform is built! I’ve been working with C# for almost 5 years and I can say that it’s almost perfect. The deeper you get into the .NET framework itself, the more you understand how flexible it is. Of course, there’re some restrictions, especially for those who move from another platform they got used to, but you can always adapt to the “.NET way” of doing something and eventually there’s nothing you can’t do.
    Also, if you write code in C++ in VS – I’d recommend to use VisualAssist extension which automates many tasks, like refactoring, code navigation, etc.
    If you write in C# – ReSharper extension makes the development process truly awesome! It writes codes for you, it formats it the way you want: naming conventions, LINQ suggestions, etc etc etc. I just can’t live without it.
    Also, there’s a plenty of cool and free extensions which helps you to configure the IDE the way you want (search Codeplex).

    BTW, I’m working on pretty big projects now, that involves complex UIs, and I don’t find VS’s Form designer slow. 4 GIG of RAM and 2.8GHZ and everything goes pretty smoothly ๐Ÿ™‚

    PS. As for the suggestion, how about rewriting zKanji in C# on .NET? ๐Ÿ˜€

    • January 12, 2012 at 1:49 pm

      >> Oh man, a couple of months with C# is truly not enough to realize how well the platform is built!

      I know that too ๐Ÿ™‚

      >> If you write in C# โ€“ ReSharper extension makes the development process truly awesome!

      I’d first learn the language itself before relying on automated features. I might be old fashioned, but I think a little manual labor is needed for learning. ๐Ÿ™‚

      >> I donโ€™t find VSโ€™s Form designer slow.

      Working with it feels slow, but that’s only compared to the designer in RS, I don’t think it is slow as such. But that flicker is killing me. ๐Ÿ˜ฅ

      >> PS. As for the suggestion, how about rewriting zKanji in C# on .NET? ๐Ÿ˜€

      That would be too big as my first project, don’t you think? ๐Ÿ˜€ BTW I started writing a program that reads in the original JMDict XML to an SQL database with LINQ to SQL, at least for now the readings, written forms and meanings of words, trying to keep the original structure in hope it’ll still be fast with SQL to search in it. (Something zkanji can’t do…)

      I might not do it the right way because it takes more than an hour to get near to the end of the data (a few minutes to do in my PERL script I use for zkanji), and then it throws an exception. At first it goes fast, but then it slows down incredibly, and each call to SubmitChanges of DataContext takes very long like it writes the whole data again and again. (It probably does because I’m working with a file but it’s only a few MBs.) ๐Ÿ˜ฆ

      My biggest problem with .NET right now is that it is huge. It has tons of classes for the same task, half of which are “deprecated”, and it’s very disheartening when I find a solution to a simple problem, then another which is said to be better, and then just another etc. and all of them seem complicated. (Though the winapi is the same. This is probably an MS thing.)

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: