44

I'm a Python programmer learning C# who is trying to stop worrying and just love C# for what it is, rather than constantly comparing it back to Python.

I'm caught up on one point: the lack of explicitness about where things are defined, as detailed in this Stack Overflow question. In short: in C#, using foo doesn't tell you what names from foo are being made available, which is analogous to from foo import * in Python -- a form that is discouraged within Python coding culture for being implicit rather than the more explicit approach of from foo import bar.

I was rather struck by the Stack Overflow answers to this point from C# programmers, which was that in practice this lack of explicitness doesn't really matter because in your IDE (presumably Visual Studio) you can just hover over a name and be told by the system where the name is coming from. E.g.:

Now, in theory I realise this means when you're looking with a text editor, you can't tell where the types come from in C#... but in practice, I don't find that to be a problem. How often are you actually looking at code and can't use Visual Studio?

This is revelatory to me. Many Python programmers prefer a text editor approach to coding, using something like Sublime Text 2 or vim, where it's all about the code, plus command line tools and direct access and manipulation of folders and files. The idea of being dependent on an IDE to understand code at such a basic level seems anathema. It seems C# culture is radically different on this point. And I wonder if I just need to accept and embrace that as part of my learning of C#.

Which leads me to my question here: is C# development effectively inseparable from the IDE you use?

19
  • 7
    Python is a dynamic language, C# statically typed (like Java), so how you code in either is very different.
    – Oded
    Commented Oct 15, 2012 at 11:00
  • 6
    @Oded: using MyType = MyNamespace.MyType;?
    – pdr
    Commented Oct 15, 2012 at 11:05
  • 4
    I don't know what it's like in Python, but in C# you can always start at global:: and work your way from there. using doesn't make anything available that wasn't before; it only makes it easier to access (as in less typing needed to use a particular class).
    – user
    Commented Oct 15, 2012 at 12:27
  • 5
    "Many Python programmers prefer a text editor approach to coding, using something like Sublime Text 2 or vim, where it's all about the code, plus command line tools and direct access and manipulation of folders and files." - Which sounds horribly inefficent to me. An IDE is a tool which helps you be more productive. Sure you can build a house with a hammer and hand saw and cut down the trees yourself, but I think you'd have a much faster time of it with some power tools and buying some pre-cut lumber.
    – Andy
    Commented Oct 15, 2012 at 13:57
  • 2
    @Andy -- I can see it sounds that way. But these text editors are actually very powerful, offering a ton of tooling and programmer efficiency features. It's just a radically different way of getting at and using those tools and features than an IDE (and one that may be more or less appropriate for certain languages/programming cultures).
    – Ghopper21
    Commented Oct 15, 2012 at 14:05

11 Answers 11

27

Visual Studio is so convenient that after working with it for a while it is difficult to use a different IDE. It has a lot of handy tools and a bunch of plugins available, so practically it has every feature you would need.

On the other hand, whatever language you learn, it is recommended to use command line at the beginning, so you can better understand how it works. C# isn't an exception.

is C# development effectively inseparable from the IDE you use?

Theoretically no, but practically yes. It is possible to write in C# using a text editor and command line, but if you have Visual Studio, you'd never do this. In fact very few programmers have ever executed C# code from command line.

BTW If you feel inconvenient with using foo, you can use the whole path when using a type.

9
  • 9
    SharpDevelop and MonoDevelop are alternative IDEs to Visual Studio.
    – Oded
    Commented Oct 15, 2012 at 11:11
  • @Oded, I've never used them but its interesting to take a look. Thanks ))
    – superM
    Commented Oct 15, 2012 at 11:12
  • Thanks superM -- can you give a flavor of the kinds of features that make Visual Studio so indispensable? I know it has very good code completion, but what else? Is it more-or-less like Eclipse for C#, or is there something more specific about it that C# developers rely on?
    – Ghopper21
    Commented Oct 15, 2012 at 11:14
  • 2
    @Ghopper21: I would suggest it's more comparable to IntelliJ than Eclipse (especially when you include Resharper), except that, in the .NET world, community plugins are generally written for Visual Studio.
    – pdr
    Commented Oct 15, 2012 at 11:27
  • 5
    +1: I agree, while you can write code at the command line with notepad, you'd be an idiot to ignore the tooling that VS or Sharp Develop brings to the table. Commented Oct 15, 2012 at 11:55
34

The idea of being dependent on an IDE to understand code at such a basic level seems anathema.

It is not a question of understanding your code: given sufficient time, you can always locate the right variable with a basic text editor or even in a printout. As far as understanding the code goes, the IDE dependency absolutely does not exist.

Locating your references efficiently is an entirely different subject: I love the ability to find usages of Java variables in Eclipse as much as I love finding declaration points in Visual Studio, for both C# and C++. I prefer spending my time coding, rather than looking for declaration points manually. This is similar to doing math: I can multiply multidigit numbers on a piece of paper, but I prefer using calculator to save myself a minute or two.

Starting at a certain "critical size" of the code, a good IDE becomes very useful regardless of the programming language. The size may vary language to language, but once you cross several thousand lines, having an IDE helps regardless of your language. This has more to do with limitations of a human mind than with a particular programming language: at some point, your short-term memory is bound to "overflow".

There are tricks letting you increase that critical size where IDE becomes useful. For example, you could follow a naming convention (Hungarian names were big in the C++ world at some point, especially among the Windows practitioners). Another common trick is qualifying instance variables with this. even in contexts where such qualification is not required.

These tricks come with trade-offs: almost inevitably, they make your program less readable by obscuring names, or inserting the explicit references the encapsulation was intended to hide. Faced with the choice, I pick clean-looking code plus an IDE over a less-clean-looking code minus an IDE. I fully recognize, however, that other people's choices may differ from mine.

10
  • 1
    I should probably have said "quickly read code"... It's quite a mental shift for me to not have all references right there in the same source file, and instead to use tools to locate those references.
    – Ghopper21
    Commented Oct 15, 2012 at 11:33
  • 5
    Not that I couldn't choose to use this idiosyncratically -- but coding isn't an isolated art and I think it's best to follow (or at least start with) the norms of a coding culture -- i.e. be "Pythonic" with Python and whatever the equivalent "C# way" is with C#. And it's clear from the answers and comments here that using a good IDE like Visual Studio is central to the "C# way" (if that's the right way to put it).
    – Ghopper21
    Commented Oct 15, 2012 at 12:50
  • 3
    @Ghopper21 Thing you'll run into with C# isn't that you can't write it without an IDE, but that the vast majority of C# code was written in an IDE and all the developers use that IDE. This fact combined with intellisense causes developers to fall into the google memory trap as studies have spoke about huffingtonpost.com/2011/07/15/… "According to the studies' findings, people with access to Google's massive web index are less likely to recall a fact when prompted; however, they remember where and how to locate that fact online" Commented Oct 15, 2012 at 13:51
  • 2
    @Ghopper21 I'm not saying this memory trap is bad, it's a source of extremely increased productivity for most which is why only those with long memories of the days when they could memorize the entire API they worked with really complain about it. I am merely pointing this out because this fact directly affects the C# code you'll read and the style and culture of C# development. Commented Oct 15, 2012 at 13:52
  • 1
    I never quite went down to bios/low level dos APIs; but my first language/environment was Borland TurboPascal; and I probably had ~90% of the language/standard library memorized at one point. The primary exceptions being related to completely failing to figure out what OO was supposed to be about. Commented Oct 15, 2012 at 15:56
8

Many Python programmers prefer a text editor approach to coding, using something like Sublime Text 2 or vim, where it's all about the code, plus command line tools and direct access and manipulation of folders and files.

That's great, but it misses the point of the VS IDE. The point of an IDE like VS is rapid development support via strong code tools like refactoring and intellisense. VS is a very very good editor for C# code.

Now C# lets you code in a style that depends on its IDE to a greater extent (you can use lots of var keywords and the like). Some people prefer to be more explicit, for instance by using namespace aliases to be clear on which namespace a class belongs to (like import in Java or Python). That's more of a coding style choice than a feature of the language.

As C# is statically typed (although with some dynamic extensions, as of v4) it's always fairly easy to find out what types are being referred to - if they're wrong the code won't compile, and VS isn't the only IDE with support for C# intellisense. It's probably the best though.

Developing C# without a powerful IDE (like VS) is rather like hammering in nails by hand when you already have a top of the range nailgun - there might be the odd time you need to do it, but professionals use the right tool for the job.

I'd say the same is probably true of Java too. If there's a powerful IDE with intellisense and code refactor tools out there you should probably be using it.

However, look at it the other way round - if you don't want intellisense, compile time code checking and code-analysis/refactoring then a bloated IDE is not the way to go, and neither is a statically typed language. I think it's the other way round:

Many programmers that prefer a text editor approach to coding don't gain as much from statically typed languages (like C# and Java) and so could be better off if they stick to dynamic ones like Python and Javascript.

I think:

  • Dynamic languages suit lightweight tools (heavyweight IDEs confer less benefit here)
  • Static languages suit powerful IDEs (tools can help with the code at the cost of flexibility)
1
  • +1 for the reversed quote.
    – fbmd
    Commented May 24, 2013 at 10:03
5

To answer your question: although it's slowly changing, the Microsoft development environment has largely been a monoculture.

This approach has many positives and negatives, which could be argued at length (e.g. consider the pros and cons of open and closed platforms, such as PCs vs an Xbox), but at the end of the day, the tooling from Microsoft is what most people use. The company has also shown that their decision making is often a kind of "give the most value to the majority of our users" process, always looking for practical compromises (most recently - consider Typescript). So basically, I wouldn't be surprised to find that the development of C# was / is done with the tooling (VS) in mind.

2
  • By the way, it could be argued that Python is also its own monoculture, given then strong adherence to what is considered "Pythonic" in coding style and approach, and the language's core design principle of having one obvious right way to do things. I tend to think programming monocultures in this sense can be very good, as it creates a coherent community and shareable code. It's just (too bad? and/or an opportunity to expand my mind?) that the Python and C# cultures are so... different!
    – Ghopper21
    Commented Oct 15, 2012 at 11:46
  • 2
    @Ghopper21 That's a very good point about Python. I think MS's version of "there should be a single, obvious way to do it" extends to the choice of IDE :)
    – Daniel B
    Commented Oct 15, 2012 at 11:56
5

Anyone bother to read way down here??

I summarize by saying the massively complex IDE functionality is indispensable and it will (should) evolve to the Zen of Sublime VimNess some day....

Our software is 129 projects of about 2M LOC. Add in the massiveness of the .NET framework and given this all I can say is the IDE is vital, transcending the motivations of this thread's question.

Insight into the Code Base

Period. You know the kinds of features we're talking about; except that its convenience becomes indispensable and essential with the kind of code base I deal with.

I write better code because of the IDE. I always add custom messages to my Nunit tests because it's easy, fast and accurate. I favor enumerations over strings due in large part to intellisense. I do not hesitate to use descriptive/long naming - a multi-line statement is composed fast and clean.

But even this smartness is too much at times. I often use good-old "find in files" text searching.

Coding help

Here is where I oft cry "enough!". Imagine a screen-full with a dozen colors of mostly obscureatta, some particular variable highlighted everywhere, brace highlighting obscuring what the brace actually is, squiggly underlining everywhere because "it" wants me to write literature not code, icons for Resharper context menus (you just gotta click it! then ignore it most of the time), a signature help popup spanning 2/3 of the screen horizontally, vertically displaying several overloads, a popup because of where you just happened to leave the mouse cursor.... I cant even seen the &^!% line*s* of code I'm working on!

Vis.Stud. needs to embrace minimalism so I can focus on coding and not go through hundreds (thousands if you count every color coding setting and all those plugins) of settings in a losing battle to reclaim sanity. A "Pareto" key would be great.

1
  • 1
    Really appreciated your thoughts here, as you seem to really "get it" in terms of both the IDE and "Sublime VimNess" approaches to things. I'm with you in all you say here. Here's hoping it comes to pass.
    – Ghopper21
    Commented Dec 6, 2012 at 13:20
4

For one, C# is not Python.. There are different design methodologies.

Now, to answer your question, it's completely possible to use your Python-esque using statements.

using FooBar=MyName.Foo.FooBar; 

It's just it is definitely not the norm because it's not nearly so easy. However, I think you should worry less about knowing exactly where exactly each class is coming from. I don't understand the entire point of doing it this way in Python though.

And also, C# is a language that lends itself very well to using IDEs to make it easier. Intellisense is amazingly simple to implement, especially compared to dynamic languages such as Ruby and Python. However, you don't have to be stuck to your IDE. I've heard of people using Eclipse. There also is of course MonoDevelop(which I use quite a lot), and you can even work from a command line. On my server sometimes, I'll be editing C# files with vi and then using xbuild to rebuild it... It's just that using an IDE makes things much easier compared to the command line for typical cases.

1

My understanding was that in Python, "everything's public" or something to that effect. In C#, the module designer decides what is public and what isn't, so when you do an import you only get the public API anyway. That could be a reason for the difference you're describing.

2
  • That's definitely a big difference between Python and C#, but it doesn't really help me understand why there is such lack of explicitness in imports. As @pbr noted in his comment, Java (which also has the public/private distinction) is similar to Python in its cultural preference for explicit imports.
    – Ghopper21
    Commented Oct 15, 2012 at 11:36
  • 5
    @Ghopper21 - The only reason to prefer explicit imports in Java (and C++ for example) is to prevent name collisions. C# made the design decision to deal with this problem via import/type aliases, since they better handle when you actually have a name collision along with the benefit of not having a bunch of boilerplate imports cluttering your source.
    – Telastyn
    Commented Oct 15, 2012 at 13:25
1

is C# development effectively inseparable from the IDE you use?

At my previous job I was mostly using vim to code in languages such as C#, JavaScript, Powershell, Perl, C++, and quite a few developers used to do something similar. The project was just too big for Visual Studio.

That said, most C# developers deal with much smaller projects and are quite happy to use VS.

0

This is an interesting view on C# development. What you are asking goes beyond C# though, if you're asking about the IDE.

Like you say, in Python, you can use various editors to write your code. You can do that with the .NET framework too. There are also other IDE tools you can use such as SharpDevelop. Visual Studio is very tightly co-developed with the .NET framework and is relatively expensive. Tools such as SharpDevelop and the "Express" versions of VS exist to entice more developers to use .NET. Essentially all an IDE does for you is provide an organised environment, usually with intellisense, add-ons for productivity and a "helper" to assemble what can end up being a very scary looking command-line to pass to your compiler. The same is true for Java, tools such as Eclipse just provide the organisation and productivity enhancements for us. Under the hood, nothing magical happens until you build or compile your project and that respect, all IDE's are just pretty faces to the unfriendly compiler.

When you talk about the "using" statement in C# and compare it to Python, it's not really the same thing going on under the hood. The using statements are used by the compiler to aid it's effort in transforming the C# code into MSIL. In MSIL, there is no "import all these classes from this namespace" directive. By the time code is at MSIL level, all the classes have been tagged with their fully qualified names. These "using" and "import" statements are to aid human readability. They are not compiler optimisation commands. After all this initial "tagging of fully qualified names" has gone on, there might be a kind of low-level "minify" to the FQNs but this is to aid the compiler/interpreter to execute faster. This is the optimisation - but there is no control of this offered to the developer, unless you are writing your own custom version of the compiler!

One final fundamental difference between all these languages mentioned on here are that some of them are interpreted by VMs, some are interpreted JIT style and some are fully compiled. How these using directives are implemented across those compilers and interpreters differs greatly.

HTH.

1
  • "These 'using' and 'import' statements are to aid human readability." -- yes, that's a key philosophical difference at work here. Readability at a textual level is a key first-order Python design principle. C# don't strictly need, but practically rely on a good IDE like VS to be "readable". Incidentally, "import" in Python is also more than about readability, unlike "using" in C#.
    – Ghopper21
    Commented Dec 6, 2012 at 13:17
0

I think that historically the answer is pretty much, yes - getting C# development up and running effectively in anything outside of Visual Studio, Xamarin, or SharpDevelop was just too much an unpleasant experience.

But recently a lot of projects have emerged that makes it easier, e.g.:

OmniSharp, provides a foundation for intellisense and refactoring, along with vim, emacs, atom, and sublime plugins. I haven't actually used it, so I don't know how well it works, but it does look promising.

Yeoman ASP.NET MVC generators, helps bootstrap a new MVC project (maybe other generators exist).

paket, an alternative to NuGet where you can actually add NuGet packages to your project from the command line, and have your .csproj files updated (although there was a NuGet command line tool, actually updating projects to use the packages was part of the IDE integration, not command line tools).

Paket has the implication that you have to adapt your source code to using it - so if you sit as the single member in a team and wants to use a text editor for coding, and everybody else uses Visual Studio, you would have to convince everybody else to adapt the solution to your needs :(

So you should be able to get up and running, but there is comparably more work to do to get your toolchain up and running efficiently.

-1

Not anymore:

http://www.omnisharp.net/

OmniSharp is a family of Open Source projects, each with one goal - To enable great .NET development in YOUR editor of choice.

It’s fun to say Cross Platform .NET. But is it reasonable for someone to develop .NET without Visual Studio and Windows?

Is it fun to do .NET on a Mac in Sublime? Ubuntu and Emacs? Windows and Atom? You can use your editor PLUS get to use great features like Intellisense (not just Autocomplete), Add Reference, Format Document, and lots more. Develop anywhere, deploy anywhere (and to Azure!)

I have tested this with subime3 and osx

More samples at

http://blog.jonathanchannon.com/2014/11/12/csharp-first-class-citizen-sublime-text/

1
  • Omnisharp make possible to use C# with text editors, like sublime and emacs. So why is downvoted?
    – mamcx
    Commented Apr 10, 2015 at 21:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.