Live data from Hacker News

Ask HN: Why use Python or similar?

news.ycombinator.com

51–60 of 72 posts

Re: Ask HN: Why use Python or similar?

#51

And I can't seem the find features of C# in Python. Which features of C# are you looking for in Python that you can't find? Also, keep in mind that something that is written in good, idiomatic C# might need to use different idioms in Python in order to make sense as a Python program (and vice versa).

I'm not the original poster, but one of the things that I can see as much easier in c# than in python is process control. The power of the .net process library [0] seems to be much greater than the power of the python process library [1]. Being able to create events on process behavior, etc is rather useful, and the python tools don't seem to give anywhere near that amount of flexibility. [0] http://msdn.microsoft.co…

That isn't really the "python process library", most of it is an agglomeration of thin wrappers around standard POSIX interfaces.

The subprocess[0] module is probably closer to what you're looking for, though it still does not operate the way you want it to. It's also possible you may be looking for something that you can get by proper use of dtrace.

More broadly, you're not looking at the C# process library there, either. You're really looking at the Windows process library. It's predicated on a different culture and different assumptions and some of its functionality may be difficult or perhaps even impossible to implement on other systems (I note the Mono implementation has several explicit NotImplemented portions).

[0] http://docs.python.org/2/library/subprocess.html

Re: Ask HN: Why use Python or similar?

#52

As an experienced Python dev who recently started programming primarily in java: You should build something big in a scripting language - probably ruby or python - the different style really will make you a better developer. I think learning java made me better ad designing classes (I never explicitly used a singleton in python before) and helped a bit in my thinking about concurrency. For python or ruby try to follo…

> I never explicitly used a singleton in python before

And that's the right way to do it. Python has global functions, Java needs singletons.

Re: Ask HN: Why use Python or similar?

#53
There are any number of reasons to use Python over C#.

(1) Ecosystem. Choice of language is often not dictated by language features, but what library features and especially third party libraries are available.

(2) Simplicity. It's a lot easier to teach Python to non-programmer domain experts than C# or Java (a major reason, I think, why Python is used so extensively in scientific computing).

(3) Not being dependent on an IDE. Using an IDE is not always an option (e.g., system administration on the far end of an SSH connection).

(4) Prototyping. Especially when doing exploratory programming, a static type system can get in the way of drafting your ideas.

(5) Extensibility. It allows you to easily provide scriptability or configurability via Python.

(6) Portability. Like most interpreted languages, Python is extremely portable across a great many architectures.

(7) Interfacing with C. While P/Invoke is much better than the JNI, Cython is easier than both.

Speed, incidentally, isn't as much of an issue in many application domains as people seem to think. If it's needed, it's frequently just a few inner loops that dominate execution time, which can be implemented easily enough in Cython.

As for Python (or any other language) lacking features that you find in C#, I think you'll find that some programmers will think the opposite (e.g., much more cumbersome metaprogramming in C#).

In short, which language to pick (insofar as that choice isn't dictated by your job anyway) is influenced by a large number of factors, which different people will weigh differently.

Re: Ask HN: Why use Python or similar?

#54
I can't see the reason either. There's a lot of hate here for "enterprisy" languages like C#, but little to back it up.

Surely, "Hello world" style programs are simpler in Python. It's probably easier to maintain and refactor C# programs due to the better tool support. The list goes on like this, with pros and cons on either side, but all in all, the differences are actually rather small: both are imperative (with some functional sauce added later), but are object-oriented, both allow you to express a large amount of logic in relatively little space (compared to e.g. Java or C++), both have a large ecosystem and both come with batteries included.

The biggest difference, really, is culture. Python has a very nice community, but unfortunately a sizeable part of this community learned Python as their first non-crap language, and thus can't imagine anything better than Python. These are the people who keep raging that non-Python programmers aren't as smart, or good, somehow, as them. It's from these people that you get the vibe that C# is somehow inferior, but you can safely ignore them.

The C# community doesn't have many such people, but in exchange it has it's own flavour of idiot: a large share of mediocre programmers who can't actually really code well, but just get by because the IDE helps them so much. These people completely depend on libraries and tools made by Microsoft and a small amount of commercial suppliers, not looking to any of the great open source stuff out there. They weren't productive doing databases until Microsoft released Entity Framework. They weren't productive doing web apps until Microsoft released ASP.NET MVC. They can't fathom sharing their work, and they think certifications are more important than great software. In the companies they work, people like this easily make manager, which makes the problem worse.

Clearly, I'm generalizing strongly with respect to both communities. I'm mostly trying to make clear that even on the community level, the difference is very small. There's awesome folks, and there's mindless morons. The kinds of awesome that exists in both communities is pretty similar, the kinds of morons are slightly different.

You'll find that, as a C# programmer, Python is very easy to learn, should you wish to do this. There's no real technical need, because C# just about equally great (I think slightly greater, but that's for religious reasons such as typing, and this thread is full of smart people who disagree). If you want to work at a shop that happens to use Python, you'll live with it. Do spend some days getting into "Pythonic" thinking. Resist putting everything into a class. Bite the bullet of lacking editor support and more concise docs than you're used to. Look past the included batteries, there's often much better alternatives outside the standard library, much more than what you're used to in .NET.

Re: Ask HN: Why use Python or similar?

#55
post #31
post #14

It is not just language. It is the platform behind language. You choose python/ruby your stack probably is opensource/linux stack. If you choose c# you probably is stuck with windows stack, (in which you don't have a lot options like open source stack).

> probably is stuck with windows stack You're also stuck with licenses for everything from your development environment to your web server, database and not to mention operating system. Compared to Python/Ruby where development cost can be $0.

You are also stuck with the costs of managing those licenses, and the risk of not being in compliance (howerever well you manage them). Both get bigger than the licensing costs when you get big.

There is also the cost hidden in "new developer? Wait a bit while I'll get another license", "what kind of replication? We don't have enough licenses", "no, you can't just create a small project (that can get huge) for solving this small problem, it can't justify the cost in licenses", and other very common situations.

Re: Ask HN: Why use Python or similar?

#56
I don't know C#, so i can't compare it with python. Some reasons why I like python:

- The REPL. I 'm so used to play around with newly installed libraries or certain features in the REPL that I'm always kind of lost when coding in a language where there is none:)

- I can do almost everything I need in one language. From simple scripts to web applications. This makes it great for rapid prototyping. I can replace parts later if there is a benefit.

- Readability of code. I really like the uncluttered visual layout and the use of English keywords instead of punctuation.

- The vast amount of solid libraries available.

- No need for an IDE. I use emacs, but I think it's great for collaboration if everybody can start right away without having to install or buy anything (at least on systems, containing python out of the box). Not really important in a business environment, but it lowers the entry threshold for people new to the language or programming.

Re: Ask HN: Why use Python or similar?

#57
I love and use both, so here's my two cents:

(Context: I am not a 'hardcore programmer'. I don't use vim or emacs because I'm simply faster/more productive with an editor that I don't need to go through a learning curve for. I am not averse to the command line, but GUIs can be advantageous at times too.)

Python is great. It's free, and available on every platform I care about. It has libraries that do absolutely everything in the world right out of the box. C#/.NET is great too. It keeps everything structured, the syntax just makes sense, and Visual Studio is the best IDE I've ever used, with great debugging tools and smooth integration of everything you require (I've even started using the built-in git control at times). However, when I was previously using a Mac as my main machine, .NET programming was largely ruled out for practical purposes. For similar reasons, finding web hosts for my ASP.NET MVC applications (which is an AWESOME framework btw) was harder and costlier. Visual Studio was free for me as a student, but the pricing would be absolutely ridiculous if I had to pay for it myself. On Python, I have a ton of choice, eg for a web framework I could choose a barebones HTTP server, or web.py, or something as heavy-weight as Django. On .NET, I'm pretty much restricted to ASP.NET, and if I don't like its defaults or the convention over configuration aspect, I'm so outta luck. In fact, for less common things, like client API libraries for specific websites, I might only find implementations in Python and Ruby, not C#. If I want help or to find documentation, the Python docs suck IMHO, but the community is amazing, whereas the community for ASP.NET isn't as robust in my opinion. There are many python experts who will happily explain obvious-in-retrospect things, whereas with .NET I'll sometimes get stuck with configuration files and what not that make no sense to me or to anyone willing to help. Lastly, if I want to quickly throw a script together for a puzzle or online coding competition, Python feels a lot more light-weight and easy to get started with than C#.

Python has a lot of downsides too, but I've got to cut this comment short now. The point is, each language has its own pros and cons - try Python for a few weeks and you might find that it isn't as one-sided as you think.

Re: Ask HN: Why use Python or similar?

#58
post #47

using System; public class Hello { public static void Main() { Console.WriteLine("Hello, World!"); } } vs print "Hello, World!" Everything is just simpler in python and ruby.

vs H in HQ9+ ( http://esolangs.org/wiki/HQ9%2B ). Everything is just simpler in HQ9+.

Hardy har, har, Giuseppe.

Simpler and easier to read.

Re: Ask HN: Why use Python or similar?

#59
post #5

Earlier quoted context omitted.

I'm writing a lot of little batch programs in my job. Like get those 1M records from db. Process them with an algorithm and write to results to this other table. I think you should write faster with Python. But performance of the processing is also important and LINQ helps a lot with the writing time.

This maybe a bit overkill, but you could take a look at ORM layers. Something like http://www.sqlalchemy.org/ instead of playing with SQL directly.

yeah, sqlalchemy core is pretty good _if you really need to build up dynamic queries_. (I haven't used the full up orm).

But if possible, I still just prefer looking at a full sql statement.

Re: Ask HN: Why use Python or similar?

#60

using System; public class Hello { public static void Main() { Console.WriteLine("Hello, World!"); } } vs print "Hello, World!" Everything is just simpler in python and ruby.

Assuming size of a pretty normal simple program is 10k LOC. Lines required to get an entry point of program, Python: 1 (0,01% of such program), C#: 7 (0,07% of such program).

Worry about the things that matter, the number of lines required to get to an entry point is not one of them. Neither is printing to the console.

And to be fair, if you are doing python seriously you would probably also have an ´if __name__ == "__main__":´ line, and a ´main()´ function called immediately from there to avoid shadowing of module variables. Assuming also you want to use the command line arguments you will have to ´import sys´ and suddenly the lines required are almost exactly equivalent short of the braces in C#.

Don't get me wrong, i absolutely love the conciseness of python but i frequently see this silly example being used which in the big picture doesn't mean anything. List comprehensions on the other hand is an excellent example of where the conciseness really shines. Really, you can do things in 1 line that in other languages takes 30. Although C# also has similar feature through LINQ so that's not a killer feature to convert someone from C# to python in particular.

Post reply on HN