Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to transition from C# to python?

i feel like i'm going back to the stone age.

how do i relearn to develop without intellisense (pydev intellisense doesn't count).. in general, how does one successfully leave the comfort of visual studio ?

like image 703
billy r Avatar asked Dec 03 '09 21:12

billy r


People also ask

How do you transition between keys?

The smoothest way to modulate from one key to another is to use a pivot chord. A pivot chord is a chord that both keys share in common. For example C major and G major share four chords in common: C, Em, G, and Am. Any one of these chords can be used to transition smoothly from C major to G major.


10 Answers

A mistake people coming from C# or Java make a lot is recreate a large class hierarchy like is common in those languages. With Python this is almost never useful. Instead, learn about duck typing. And don't worry too much about the lack of static typing: in practice, it's almost never an issue.

like image 133
static_rtti Avatar answered Oct 01 '22 01:10

static_rtti


Python has rich "introspection" features. In particular, you can find out a lot about built-in features using a command called help() from the Python command line.

Suppose you want to use regular expressions, and want to find out how to use them.

>>> import re
>>> help(re)

You get a nice display of information, automatically shown to you a page at a time (hit the space bar to see the next page).

If you already know you want to use the sub() function from the re module, you can get help on just that:

>>> help(re.sub)

And this help() feature will even work on your own code, as long as you define Python docstrings for your modules, classes, and functions.

You can enable features in the vim editor (or gvim, or vim for Windows) that enable an "IntelliSense"-like autocompletion feature, and you can use Exuberant Ctags to generate hyperlink "tags" to let you navigate quickly through your code. These turn vim into something that is roughly as powerful as an IDE, with the full power of vim for editing. (There isn't an explicit refactoring tool built in to vim, but there are options available.

And as others have noted, you can get IDEs for Python too. I've used the Wingware IDE, and I recommend it. I try to do most of my work with free, open-source software, but that is one piece of proprietary software I would be willing to buy. I have also used Eclipse with the Pydev plugin (I used its refactoring tool and it worked fine).

P.S. Python has a richer feature set than C#, albeit at the cost that your code won't run as fast. Once you get used to Python, you won't feel like you are in the stone age anymore.

like image 40
steveha Avatar answered Oct 01 '22 00:10

steveha


I recently learned python with a strong C# background.

My advise: Just do it. Sorry, couldn't resist but I'm also serious. Install python and read: Python.org documentation (v2.6). A book might help too -- I like the Python PhraseBook. From there, I started using python to implement solutions for various things. Most notably, ProjectEuler.net questions.

It forced me to consider the languages and built in data structures.

Python is truly easy to use and intuitive. To learn the basics, took me about an hour. To get pretty good with it, took around 5 hours. Of course, there is always more to learn.

Also, I want to note that I would discourage using IronPython or Jython because I feel learning core, regular python is the first step.

like image 45
Frank V Avatar answered Oct 01 '22 02:10

Frank V


One step at a time?

Start off with simple programs (things you can write with your eyes closed in C#), and keep going... You will end up knowing the API by heart.

like image 23
Oded Avatar answered Oct 01 '22 00:10

Oded


<rant>

This is sort of the reason that I think being a good visual studio user makes you a bad developer. Instead of learning an API, you look in the object browser until you find something that sounds more or less like what you are looking for, instantiate it, then hit . and start looking for what sounds like the right thing to use. While this is very quick, it also means it takes forever to learn an API in any depth, which often means you end up either re-inventing the wheel (because the wheel is buried under a mountain worth of household appliances and you had no idea it was there), or just doing things in a sub-optimal way. Just because you can find A solution quickly, doesn't mean it is THE BEST solution.

</rant>

In the case of .NET, which ships with about a billion APIs for everything under the sun, this is actually preferred. You need to sift through a lot of noise to find what you are aiming for.

Pythonic code favors one, obvious way to do any given thing. This tends to make the APIs very straight forward and readable. The trick is to learn the language and learn the APIs. It is not terribly hard to do, especially in the case of python, and while not being able to rely on intellisense may be jarring at first, it shouldn't take more then a week or two before you get used to it not being there.

Learn the language and the basic standard libraries with a good book. When it comes to a new library API, I find the REPL and some exploratory coding can get me to a pretty good understanding of what is going on fairly quickly.

like image 29
Matt Briggs Avatar answered Oct 01 '22 01:10

Matt Briggs


You could always start with IronPython and continue to develop in Visual Studio.

like image 35
Josh Avatar answered Oct 01 '22 00:10

Josh


The python ide from wingware is pretty nice. Thats what I ended up using going from visual studio C++/.net to doing python.

like image 33
John Schroder Avatar answered Oct 01 '22 01:10

John Schroder


Don't worry about intellisense. Python is really simple and there really isn't that much to know, so after a few projects you'll be conceiving of python code while driving, eating, etc., without really even trying. Plus, python's built in text editor (IDLE) has a wimpy version of intellisense that has always been more than sufficient for my purposes. If you ever go blank and want to know what methods/properties and object has, just type this in an interactive session:

dir(myobject)

like image 29
twneale Avatar answered Oct 01 '22 02:10

twneale


Same way you do anything else that doesn't have IntelliStuff.

I'm betting you wrote that question without the aid of an IntelliEnglish computer program that showed you a list of verbs you could use and automatically added punctuation at the end of your sentences, for example. :-)

like image 23
Ken Avatar answered Oct 01 '22 02:10

Ken


I use Eclipse and PyDev, most of the time, and the limited auto-completion help that it provides is pretty useful.

It's not ever going to come up to the level of VS's IntelliSense, and it can't, because of the dynamic nature of Python. But there are compensations, big ones.

The biggest is the breaking of the code-compile-test cycle. It's so easy to write and test prototype code in IDLE that very often it's where I go first: I'll sketch out and test a couple of methods that have to interoperate, figure out that there's something I don't know, learn it, fix my test, and then port the whole thing over to PyDev and watch it work the first time.

Another is that it's a lot simpler. It's really important to know what the standard modules are, and what they do, but for the most part that can be picked up with a little reading. I only use a small handful of modules in my everyday programming - itertools, os, csv (yeah, well), datetime, StringIO - and everything else is there if I need it, but usually I don't.

The stuff that it's really important to know is stuff that IntelliSense couldn't help you with anyway. Auto-completion isn't going to make

self.__dict__.update(kwargs)

make a damn bit of sense; you have to learn what an amazing line of code that is, and why you'd write it, by yourself.

Then you'll think, "how would I even begin to implement something like that in C#?" and realize that the tools these stone-age people are using are a little more sophisticated than you think.

like image 42
Robert Rossney Avatar answered Oct 01 '22 02:10

Robert Rossney