English 中文(简体)
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 ?

最佳回答

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.

问题回答

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.

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.

<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.

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

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

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)

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. :-)

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.

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.

I m not too familiar with Python so I ll give some general advice. Make sure to print out some reference pages of common functions. Keep them by you(or pinned to a wall or desk) at all times when your programming.. I m traditionally a "stone age" developer and after developing in VS for a few months I m finding my hobby programming is difficult without intellisense.. but keep at it to memorize the most common functions and eventually it ll just be natural

You ll also have to get use to a bit more "difficult" of debugging(not sure how that works with python)

While your learning though, you should enjoy the goodness(at least compared to C#) of Python even if you don t have intellisense.. hopefully this will motivate you!

I ve only ever used IDLE for python development and it is not fun in the least. I would recommend getting your favorite text editor, mine is notepad++, and praying for a decent plugin for it. I only ever had to go from Eclipse to Visual Studio so my opinions are generally invalid in these contexts.

Pyscripter does a reasonable job at auto-completion/intellisense. I ve been using it recently as I started to learn Python/Django, where I ve been mainly a C# developer for the last few years.

I suggest going cold turkey - languages like Python shine with great text editors. Choose one you want to become amazing at (vim, emacs, etc.) and never look back.

I use Komodo Edit and it does reasonably good guessing at the autocompletion.

Others have suggested several editors that have intellisense-like capabilities. Try them out.

Also install ipython and use that to learn the language interactively. It is like a souped up version of the regular python interactive shell with lots and lots of added capabilities, and one of the most useful it its extensive context sensitive tab-completion and help.

For example if you type

import r<tab>

it will show all the modules you can import starting with r

import re
re.<tab>

will show all the objects in the re module

re.compile?

will show the docstring and other information about the re.compile function, automatically piping it through a pager if it is longer than a screenful.

re.compile??

will show the source code as well, if available.

Using this I find it is much faster to switch to ipython and query objects directly than it is to look up anything in the docs. You have access to the usual python help() system as well.

ipython has lots and lots of other features - far too many to cover in a short post.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签