151 points · by thedigitalengel · 16y ago · 218 comments
I love C. I like C++ too. I used to write a lot of Java when I was a kid (as in high-school kid) but now that I've written quite a bit of C and C++, Java seems more like a toy language. I did enjoy Java back then, however. I yet to do any major work in C#, but it seems to be a powerful language, especially when handling certain kinds of complexity.
I've been learning LISP on weekends for two weekends now, and I find it interesting. I know little bits of Haskell (am planning to learn it later this year) and seem to like it too. Maybe I like the idea of liking Haskell, I'll know for sure once I actually start writing Haskell.
Coming back to the point - I don't like Python. I've never liked it. I've tried working on various Python projects but have always found some or the other excuse to prematurely back out. And mind you, I love coding - I spend most of my time writing code or learning new stuff about code.
My question to the hardcore python lovers is this (and mind you, by hardcore I mean the kind of people who wrote Exaile, not the kind who hack up a Python script every now and then to organize their iPod): No doubt many of you have come from C / C++ / LISP backgrounds. What is the paradigm shift you experienced? I look at a piece of C code in a certain way - how do I look at a piece of Python code? How do I think about Python? How do I think in Python (copied that one from Bruce Eckel)?
I couldn't believe all the junk Java required of me when I took a stab at it. It's like being confronted with some unhelpful bureaucrat: I know what I mean, they know what I mean, but they're damn well going to make me trudge through all the nonsense so that what I mean is turned into something the bureaucracy understands. The linked NLP examples are great for illustrating this.
The following code is readable and I have required a variation of it in a program before:
sorted([ord(c) for c in
set('letters in this sentence') & set('and this one')], reverse=True)
Doing it in Java would be a chore now. (use 'clojure.set)
(reverse (sort (map int
(intersection (set "letters in this sentence")
(set "and this one")))))
Edit: Take two... (use 'clojure.set)
(->> (intersection (set "letters in this sentence")
(set "and this one"))
(map int) sort reverse)
(experienced lispers, feel free to make this more idiomatic)Scala isn't as succinct, of course, but it gets much closer!
A language that needs you, the client programmer, to define getFoo () and setFoo () methods manually can't be right.
It seems like Java wasn't defined in order to be an efficient for a three-person shop to hack in. It was meant to be efficient for a 40 person shop to build code as a team that they can maintain.
That said, I dread going back to my Java projects and updating them, even though I tried to maintain best practices in order that updating be as simple as possible. I've been immersed in php and javascript lately, so we'll see what it's like to go back.
If you want Java without the unwieldiness, try Groovy. It's Java with a ton of syntactic goodness added; for instance, the default variable scope is "create a getter and setter which I can optionally override." Groovy interoperates well with Java libraries. The downside is that it's a dynamic language, so there is a significant performance penalty.
what do you think of ooc-lang syntax? http://ooc-lang.org/
I think it's fairly clear from context that he/she means, "not a lot of red tape", rather than a reference to specific language features.
Python for me is the imperative language (with some functional features) closest to pseudocode.
I've done some Django programming in the past. A view gets a request object (pardon me if I'm wrong or if this has changed recently) and is supposed to then render the response (or something similar, I don't remember exactly). Now what is a request? If Django were in C, I would know what a request object really was, grep for it, and look up the header file. If request has a GHashTable named post_data, I don't think I need two guesses about what it exactly is. Same goes for C++ and C#.
Then you've inconsistencies. The same method may return a string object or an integer on different calls. And this happens in practice - I remember when I was (trying to) model a relational database in Django, I found a ManyToMany field returning (when invoking values ()) a list of dictionaries instead of a list of Model objects (which I was expecting).
Of course, if I was not dumb enough to not read the documentation I might not have stumbled; but the point is that Python allows this to happen. And since I don't have the benefits of a compiler, anything other than basic syntax errors (the ones I can catch by calling py.compile) explode at runtime.
The thing I've begun to notice that scripting languages tend to require you to hold the entire structure of the program in your head as you code. In C++ you know that unless you've gone out of your way to do some casting magic, a string get_foo () will always return a string. And you can always do get_foo ().c_str (). In python you're never sure.
The inconsistencies you mention are (in a well written code base) very rare. If you call a method get_name() odds are you are going to get back a string. If you seem to randomly get back an int or a dictionary or a datetime object it's a pretty good sign the code is foobar'd. Good Python programmers don't abuse the dynamic nature of the language. Methods should return predictable types (documentation is important), it might return different types depending on the input but this should be documented and obvious (say a parse date method that returns a datatime object if you pass it a string containing a date and time). The values() example you use is very clearly documented as returning a ValuesQuerySet that supplies dictionaries not models (http://docs.djangoproject.com/en/dev/ref/models/querysets/#v...).
In a number of years using python, the standard library and 3rd party libraries I've never been left wondering "If I pass X to this method what the hell type am I going to get back". Just like in C/C++ I need to remember it returns a list or a string or a dictionary but that's usually where the mental overhead stops.
Python is dynamic which means it's flexible. Flexibility is usually reached by sacrificing simplicity so Python encourages testing and good documentation. I would argue that these are both necessary features of any good code base, Python is just more upfront about this than a number of languages.
The purpose of this thread was merely to gauge what kind of paradigm shift people who were used to programming in C or C++ generally experience when they move to Python. Some people seem to find making the jump easier than others - I personally have found it difficult and have made little progress so far. Since I generally consider myself good with computers, I find this a little unnerving.
http://norvig.com/21-days.html
From your comments, I kind of get that you want to be a real good programmer, and part of being a good programmer is to understand the different way you can wire bit and pieces together in the many different languages. I had a similar experience as you in that I went from C->C++->Java->Javascript->Scheme->SML->Python. I can definitely tell you that learning Scheme and SML first helped me tremendously in understanding dynamic languages in general. In more concrete terms, understand typing rules has helped me how to debug a program when I mess up in Python. For example, in SML, I can completely omit type annotations and the interpreter will infer the right type for me at parse-time, and that each function or statement must only return 1 type.
In dynamic languages such as Python, you can still do what you can do in SML or Haskell, but the runtime system makes no guarantee that your program as it is written is type-safe when the interpreter parses all your source files. Type checking is done at execution, when the code path in question is exercised. However, if you THINK about how the types are infered in SML when you write in Python, you generally will not run into TypeErrors.
The same goes for functions that return different types. To prevent tripping up with these functions, just apply what you've learned in Haskell or SML when you are debugging library functions that do this, and avoid writing functions that return different types.
Django in particular has several additional advantages:
• it has an "interact" mode that pops you into a Python REPL so you can poke at all of this stuff interactively instead of having to save a source file and hop over to your browser;
• it has really first-class documentation;
• if you raise an exception in debug mode, the traceback includes dumps of all of the objects mentioned on all the levels of the traceback stack, along with a few lines of source code from the stack frame;
In short, Python offers much more power to undertake the kind of analysis you were wanting to do than C or C++, but you have to do it dynamically, instead of statically.
If Django were in python, you wouldn't even have to grep
>>> import django.http, inspect >>> print inspect.getsource(django.http.HttpRequest)
I really like using a dynamic language for some tasks. I almost never use C, C++, or Java for any task I hope to start and complete within a day. Those jobs are small enough it's easy to keep track of what you are passing around.
I spent 6 months writing all of my utilities in Python. I tried very hard to like it, but it just didn't tickle my fancy. I do like perl and ruby for a dynamic language. I think perhaps the issue is, if you are like me and you don't like using dynamic languages for large programs, the extra clarity of python isn't enough of a added bonus.
import pdb; pdb.set_trace()
which makes it enter the debugger at that point, and I simply inspect the object that I'm really getting, looking at what it supports, the documentation on its methods, etc.Doing it this way is not always feasible, since sometimes there's a prohibitive amount of setup code that needs running before you can get a real object. For short code paths though, like Django apps, it works really well.
def foo (self, stream): What is stream here?
void foo (std::ostream &out) { out << "bar" << endl; }
Hope you get the point.
$stdin.read.split.each do |w|
puts w if w.match(/ing$/)
end
or as a single 57 column line: $stdin.read.split.each { |w| puts w if w.match(/ing$/) }
we can also use the match operator: $stdin.read.split.each { |w| puts w if w =~ /ing$/ }
I'm inclined to assume that the other language examples are also suspect.foreach line [read stdin] { foreach word [split $line] { if [string match *ing $word] { puts $word } } }
The one thing that gets me is the "it's already been done" mentality. If you love Tcl then you want to create things in Tcl for the world to use. I have thrown out a couple ideas like "mailman in Tcl" or "nagios in Tcl"...but I always get "it's already been done". Sure, I could have done it anyway, but it gets your spirit down when you hit that wall. I know they have been done with other languages. Let's do it in Tcl to see if it can be done better!
The whole scripting language issue is a complicated one imo.. People want to either use 100% scripting or 100% system (i.e., C), which is not alright. Combine scripting & system according to your needs. This is why I like Tcl the most: It prevents you from using it where there might be computational bottlenecks (e.g., in algorithms). It is meant to complement C, not replace it. Anyway this is a separate thread.
[read stdin] returns a string (not a list of strings), which is parsed as a list when you try to loop over it. The parsing breaks the string into a list of words, so the second loop is redundant. The parsing could fail if the input file isn't valid list syntax (unmatching {}'s). [split _] makes it safe.
foreach word [split [read stdin]] {
if [string match *ing $word] { puts $word }}
I love Tcl too! Tcl is a scripting language for C, Python is less-powerful version of Lisp.First off, Java isn't a toy language. You've characterized it improperly. Java is a bureaucratic language. You have to cross your t's dot your i's, fill out your requests in triplicate at the FactoryFactoryFactory to get the objectOfYourDesire. Why is this so?
This comes back to how C++ works on projects, especially large projects and midsize projects with a couple mediocre programmers thrown in (because, in commercial software development, you rarely get control of your team). C++ does not work well for large team development unless 1> You have very capable people 2> and you can fire everyone who steps outside the "defined okay subset" of C++ you use on the project. The language is too big, certain parts make it too uncertain, etc, for people to just willy nilly use all the language features. So Java, is basically Sun's "redoing" of C++ where they took its wild west nature, and made a BureauDisney version where you can't do a dozen things that happens in C++ all the time when good programmers go off the reservation or bad programmers enter the equation at all.
C++ has uses, but it's the sulfuric acid of programming languages: you have to have good personnel control and fire those who screw around outside the boundaries of the right style. A programming group with one guy programming like C with classes and another guy programming like it's Ocaml without garbage collection, and you're in for a mighty piece of hell.
So that's where Java came from. That's why it is what it is, and I hope I've highlighted a non-business issue with C++ that comes up from it's overabundance of "understanding breaking powers" which don't mess well with total programmer freedom.
Now lets look at what python was, and what it is now: Python was originally designed as a substitute for the pascal/BASIC line of programming languages (specifically a language called ABC). It was designed to be very very clear. It still is very very clear. It is still quite terse compared with C++/Java/C, but it's wordier than perl and ruby, but very much clearer for even non-python programmers to decipher much of the time.
Over time, it grew into an Application development and webserver development language. Why?
It has a very easy way to interface to C code. This is important, because C does great module level integration, but once you get at the system level, you start to get issues with namespaces, tracing bugs, etc. So python became an alternative for tying C code together.
It writes very quickly. While you may not understand how to write it quickly yet, usually python/ruby/perl will be quite a bit more productive on a feature basis than Java/C#, and tons more productive than an equivalent C/C++ project. This has to do with the fact it takes very few lines of these languages to "do a job".
For you currently, you're possibly less productive in python right now than you are in C++; I've honestly found this doesn't hold true more than 40-80 hours into learning python development while doing a real project for almost anyone who can handle commercial C++ software development. The C++ people do python faster than they do C++ and it has many fewer issues in the end than C++ they would have wrote. We use weave.inline or something else to speed up the inner loops with some native C, if even required for that application, and all is good, it works just as fast for the user or application, and was completed much faster with much less obtuse bugs.
If you spend those 40-80 hours on the language, you too will likely be a faster developer in python than C++ for many features.
Some tips: You are not doing C, you are not doing C++, you are not doing Java. Don't pretend you have to do the bueracracy that those languages require. If you write a python program with absolutely no functions, it will run just fine. So if all you need to do is process a small amount of text or open a little server, you can do this in a flat file with just a series of lines of code striaght out of main() in a C program. However with the size and completeness of the python standard library, you'll rarely have to write the rest of the functions.
Secondly, it's important to learn idomatic python today. If you write things like "it's supposed to be" in python today, you get speed on par with C/Java (or only 3-5x slower), and it's really freaky to see an interpreted language do that.
Thirdly, it's important to learn and use the standard language rather than writing code. Python module of the week blog is a great resource to do this: http://www.doughellmann.com/projects/PyMOTW/ Much of python's power comes from a stupidly complete standard library that does much of what you need to do so allows you to write 20 line programs.
Lastly, learn easy ways to fall back on C/C++ in python. This way when you use python for an application it turns out it's too slow for, you can still add a bit of C/C++ to get the speed you need. You can embed C++ inline and have it compiled on the fly with weave, so I suggest you learn that.
http://www.scipy.org/Weave for getting it
http://www.scipy.org/Cookbook/Weave for examples of use
http://www.scipy.org/PerformancePython for examples of how fast this runs vs other things.
This is such an absolutely fantastic way of succinctly describing why I dislike Java so much. Bureaucratic!
Absolutely fantastic post, get this on a blog somewhere. I seriously wish I could upvote you more.
It's like a security blanket for me.
Not to be a prick, but if you're having "typing" problems with Python, you're using it wrong.
Types are almost irrelevant in Python. What matters is whether, in a given situation, the method you're calling is supported and does what is intended. The actual type/class of the receiving object doesn't really matter, ditto for any arguments you pass to the method.
While this may seem highly unsafe and brittle, it has important benefits. You can just hack up some code that "just works" in a few minutes, without having to sacrifice a goat to the compiler first, making sure that all the correct types are specified, subclasses are defined, interfaces are implemented completely, etc. The rigid type systems in other languages often require this and more; making changes to your software becomes a chore. Rapid prototyping this is not.
In Python, when used correctly, you don't have this problem. Write a bit of code, write a test, run it, and decide what to do next. Ideal for testing out ideas. It doesn't work? Throw that shit out and write something else; two minutes later you'll be testing your new code again. Yes, you do need to have unit tests, but the same is (or should really be) true for most languages. Just because something compiles, doesn't mean that it does what you want. (Except maybe in Haskell. :-)
Interestingly, the quickly-written prototype might well be good enough to become the actual production code, with some additions. Just keep you tests up-to-date, for reasonable use cases, and there's no reason why your code shouldn't work in real life. Sure, that function foo(x) that wants to call x.bar() will fail if you call it with an x that doesn't support the bar() method. So don't do that, then! ;-)
Anyway, to summarize, I personally would much rather have Python's flexibility, paired with unit testing, than Java's lack of flexibility paired with compiler checks.
Here is a link to doctests. There are godly, and unlike any testing library, in that they aren't a library, they're a comment scanner: http://docs.python.org/library/doctest.html
Smallest amount of rigmarole required to make testing happen I've seen in any language.
Java is almost untyped by comparison. Languages like Ocaml and F# occupy a middle ground.
Take the Java web framework, Play, as an example. http://www.playframework.org/
All of Java's features conspire to create a language that's pretty verbose and doesn't do a lot to make things easier for you (aside from simple object orientation). If you like spelling everything out in excruciating detail, that's good. If not, the language doesn't want to twist your arm, but it's certainly not going to do anything to help you.
It'll work from Hong Kong, and probably most places in the world, but if you cross the Chinese border into Shenzhen, you'll get "The connection has been reset". Same with other places in mainland China I've been.
This is the best tip that could be given. In the SICP course in Berkeley CS class, the instructor puts it as
"Don't ask me what the language will do if you do something stupid, the answer will always be either you would get an error or the computer will do something stupid. Don't try to convert java code into LISP, try to think in the language."
Python was so much more high-level than all these other languages that it was staggering. It was pretty weird to use it at first. Where are all the declarations? What are these "lists" and "dictionaries"? You mean I can just stick any old thing in an object or even a class? Etc.
Soon it became obvious how much more powerful this new language was, and I enjoyed replacing reams of Pascal/C code with a few lines of Python. I tried to use it at work too, but failed because it was considered "unmaintainable" by the powers that were (this was around 1999-2000). Of course, this just fueled the feeling of having an obscure but superior language rebelling against the big evil statically typed empire. :-)
Anyway, this used to be some of the appeal of Python. I suppose it still applies to some extent, although since then, Python has been passed left and right by languages that are more powerful, more flexible, more functional, more "fun", and whatnot. Nowadays there seems to be a meme going around claiming that e.g. Ruby is fun and flexible, while by contrast Python is boring and conservative. It wasn't always like that. I distinctly recall people discovering Python and exclaiming that "programming is FUN again!".
Then again, all of these things are in the eye of the beholder, mostly. If you don't like Python, no big deal, especially if you have both lower-level (C, C++) and higher-level (Lisp) languages at your disposal. (Personally, I used to think that Ruby was butt-ugly and uninteresting... these days, I have taken more of a liking to the spirit of the Ruby community, which (perhaps ironically) reminds me of Python's in the 1990s.)
I prefer Ruby, but appreciate Python and Perl. I come from C/C++ coding for 14 years.
Examples.
In Java, accessor methods are considered good style. In Python, directly accessing a member is better. (more concise, makes client code clearer.) If you need to do magic, you can use properties.
In C++ and Java, you use inheritance to denote which classes have a given behavior. In Java, you also use interfaces. In Python, you simply give a class the needed method(s). (I.e., you use duck typing.) That flattens or removes lots of class hierarchies. If you need to do magic, you can use isinstance(), issubclass() or hasattr().
In Python, you use the built-in types a lot. Many problems decompose easily to lists, sets and dictionaries. That reduces code dramatically. Java and C++ STL's containers, in contrast, are so clumsy they make me look for ways to avoid them. If you need to do magic, you can subclass the built-in types or build new types with the same methods as the built-ins.
Try the other two scripting languages - Ruby and Perl. I would prefer Ruby. See if you like the way things are done there.
If you find that you are more at home with this language than Python, try analyzing what makes you prefer it over Python.
I would suggest you to start with the basics of the Ruby language, and then try building a simple web app with Sinatra. I find the Ruby style much more comfortable than Python.
But if you don't like any of these languages, its still well and good. If you get can shit done with C#, thats all it counts.
It's basically a language written by a group of people who don't trust you (as a Python user) to be knowledgable and educated. Decisions have been made based on the assumption that you are bad at your job.
Now, everyone seems to comfort themselves with the notion of making it “easy for maintenance”; repeating “I am smart, surely, but not everyone can be as smart as I am.” But this is ultimately a dodge that feeds into the problem endemic to our industry: a disdain for everyone else and everyone else's methods if they differ slightly from our indoctrinated best practices.
I agree about closures, but why lambdas would be so much better than named functions (already available)? I think named functions help code readability, which is among Python's top goals.
Because sometimes you want to conditionally create functions on the fly. Named functions are a very awkward way to do this.
It is unfortunate that we even have to have this argument. Anyone with significant experience in functional programming can tell you how useful unnamed functions are.
And it's important to realize they are not necessarily anonymous in local scope. They're anonymous in the global scope.
> I think named functions help code readability, which is among Python's top goals.
Anonymous Lambdas need not be a detriment to readability. Why do you think it would be otherwise?
Perhaps I'm way off here but the languages seem to me to show some of their cultural heritage. Python has a blunt & minimalistic Dutchness about it while Ruby has a Japanese elegance and style.
There are a number of things that made me think Ruby was made by a less astute designer. The 'end' everywhere feels bad in a world where I know both "}" and a newline can accomplish the same thing but with less typing and screen clutter. Also do not like Ruby's dropping of ()'s from fn call statements, because it blurs the boundary with non-calls and non-expressions and control flow keywords. I also feel Ruby encourages a certain kind of DSL creation which makes the code harder to read and maintain. I also don't think every app or library needs to export a DSL into client space. It's better if the interface it publishes still looks and feels like the prog language used.
That said, I acknowledge Ruby has good qualities. Python is not perfect, but to me it gives the better designed feeling. Actually the Lisps seem to be the most elegant and powerful. Love their regularity and power but not (yet) all the parentheth everywhereth.
Ruby is more fun,but python is more mature. In the end - whatever gets the job done right?
I really enjoy the pretty simply object model, the message passing OO, and blocks.
An interesting point that I read somewhere the other day, from someone who codes in a lot of both: Ruby (to him) is kind of ugly, and Python is very pretty. Yet, the exact parts that make Ruby ugly allow it to have _awesome_ libraries. Python, with its rigidity, means that the core language is great, but the libraries end up being worse because of it. He uses RSpec as an example, specifically. So for him, Ruby ends up being better to use, even though he likes the Python language better.
Apropos: Does Ruby optimize tail calls?
Ruby: a = %w( apple pear orange )
Python: a = [ "apple", "pear", "orange" ]
Ruby: a=%q/O'Malley says "Hello"/
Python: a = "O'Malley says \"Hello\""
Python lets you use "'" or '"' as the delimiter, which solves 80% of these cases - but why not generalize the concept, as Perl and Ruby did?In Ruby, the last expression in a function is the return value; in Python you must use the return keyword, even though there's no ambiguity.
For example, if there's a function composed entirely of print statements, the last expression evaluated will be the expression in the last print statement executed. But, that means you have to know that 'print' is a statement and not an expression, and that the right-hand side of the print statement is in fact an expression.
In ruby, actions like prints and assignments are side-effects and always evaluated as expressions. So if puts is the last expression in a function you'll get the return value of puts (which is usually nil I believe). That's pretty simple.
a = '''O'Malley says "Hello"''' a = "apple pear orange".split() Ruby: a.map{|i| i+1}.reject{|i| i%3 == 0}.map{|i| i*i}
Python: [i*i for i in filter(lambda i: i%3 != 0, [i+1 for i in a])]
Please ignore the fact that the whole operation can be simplified mathematically - nontrivial map-grep-map operations do occur.I find the Ruby version clearer because it proceeds from left to right like a shell pipeline.
This is easier to read and understand, only goes through the list twice, and loses nothing in terms of power:
[j*j for j in [i+1 for i in a] if j%3 != 0]
(And for any given operation, there's very possibly a cleaner way to abstract out the inner list comprehension, which would again make it a lot nicer.)In general, I don't see much of a reason to use filter/map/etc in Python: weak lambdas mean they're not terribly powerful. List/sequence comprehensions can do everything they can do with cleaner syntax and/or fewer operations.
This, I think, is actually at the core of this whole discussion. The Ruby/bash approach makes sense if you're used to working with sequences like Ruby/bash do. The Python approach is more natural to me though, because I've written a lot of Python. (And having spent the last year writing a lot of Ruby, I still find the Python approach cleaner/easier to understand at a glance.)
@a.map({ $_ + 1 }).grep({ $_ % 3 != 0 }).map({ $_ * $_ })
Alternately, using the feed operator ==>: @a ==> map { $_ + 1 } ==> grep { $_ % 3 != 0 } ==> map { $_ * $_ }
And, if your code being readable to people who've never used Perl 6 and know nothing about it isn't a concern, you can use the much more concise Whatever star notation for closures: @a ==> map * + 1 ==> grep * % 3 != 0 ==> map { $_ * $_ }
Using Whatever for the last one would neither work nor be readable(although you could do "* 2", but that's still suboptimal for readability), since the last "" in " * " would be interpreted as a second parameter.If the preceding notations for anonymous functions have been too implicit for you, then you can use pointy blocks(or just plain anonymous function declarations).
@a ==> map -> $i { $i + 1 } ==> grep -> $i { $i % 3 != 0 } ==> map -> $i { $i * $i }
Or, you could use hyper operators instead of the maps: ((@a >>+>> 1).grep: {$_ % 3 != 0}) >>**>> 2
The hyper-operators extend the scalar operators "+" and "*" to lists. Since the ">>" point to their operands on the right side, that operand will be extended to be as long as the other side, allowing you to use a single scalar as the right-side element.This is an excellent point. Ruby code can be some of the cleanest, most readable functional code there is. I have these kinds of chained pipelines in my Ruby code all over the place and they're much easier for me to follow than similar expressions in Lisp or Haskell and than Python's comprehensions.
map { $_*$_ } grep { $_%3 != 0 } map { $_+1 } @a
Interestingly, in this particular case Perl seems to have way less syntax than ruby or python, which I find rather ironic. It does have to be read backwards though, because of the syntax of map and grep...Then looking into python, I saw the same philosophy as C; A struct or an array? Use a nice dictionary, set, tuple or a list, nicely kept under the [ ] brackets. Throw them in for loops without the iteration integer. Its just all the same things I do in C but easier, with no cryptic idioms. That's why I love it.
I have 2 choices of languages for all my projects: C and Python
A few years ago I was thinking about what would be the minimum set of languages that would be good to know in order to be able to do almost anything you wanted, and do it well, and to always be employable. I ruled out 1 language alone because of the C phenomenon: there's a whole class of software where today C is the best choice, and a whole different set where C is a bad choice. Therefore, the ideal set was 2+ with C being one. I ended up settling on C, Java and Python. Java for enterprise/BigDumbCompany work, but also because there's a lot of great tooling and innovation happening in the Java space more so than other langs. Python for the role of glue and prototyping and high level no boilerplate bureaucracy but where you could still trust every developer using it. Ruby could probably fill that role decently instead, except be a little better or worse in diff areas.
C, Java, Python
Then I found out that Google had picked these three as well. Nice!
I had forgotten about JavaScript, I guess I considered that one a no-brainer on the browser side. However, the line blurs between C and C++, especially if you use the extra stuff only tactically as needed rather than a hard-core-always-OO-and-templates approach.
* C for (somewhat) bare metal programming (OS, embedded)
* Java for high-level with rubber edges and safety wheels, esp huge codebases in enterprise IT shops with Joe Blub coders
* Python for high-level agile w/solo or small elite teams (calling out to C bits where beneficial)
My language-choice algorithm is:
sh + unix DSLs -> Tcl/Tcl+C -> SML/Haskell/Scheme -> C -> *
Where '*' is whatever language has a library I need, or a language that I'm required to use.
But I've grown to like the simplicity of Python. One thing I don't like is its threads implementation, however. Because of the GIL, multithreading (GUI + background thread) just doesn't work right. Maybe I'm using it wrong?
The Python community seems to be warming to the importance of threads. There are several efforts breaking their swords against the GIL nowadays (Unladen Swallow being the most prominent), and Antoine Pitrou wrote a new GIL to help improve contention [1]. With any luck, by the end of the Python Feature Freeze, there will be some significant headway towards efficient handling of threads within Python, but I'm not holding my breath yet ;)
I have exactly the opposite heuristic for syntax. The only thing worse than semicolons and curly braces, are `begin' and `end'.
I never met a hardcore C++ guy claim they like C++
> by hardcore I mean the kind of people who wrote Exaile
I think Python weren't meant to write desktop music players. Stuff like Zope are hardcore.
I'm more like a hardcore C guy.
I do know a fair bit of C++ though. Perhaps C++ would've been better if compatibility with C was not kept as a fundamental goal. Just a personal opinion.
Qt does an amazing job of taming C++. I used their framework for some GUI design and loved it.
So, no you are not a bad person. If you've given Python a honest attempt (took me a year to do that, I had whitespace hangup that was hard to get past), then you aren't missing anything either. Python just isn't the language for you. Move on, be happy.
Of course, I don't have any pretentions of being a "good person" either.
Came from C++, learned Perl, got a job writing Fortran, learned Lisp. When hating on Perl came into vogue on the internet, I said to myself, okay, I will learn Python as a Perl replacement. It is a decent Perl replacement, what with all the libraries and the fact that it is shebang-able.
Now that I've dispensed with background, what I don't like about Python:
1. Assignments don't return values. I hate this. An example. I would like to write:
if (m = re.match("woo, regular expression")):
do some stuff with match object
Instead m = re.match("woo, regular expression")
if m:
do some stuff with match object
This obscures the fact that I only care about this match object if it evaluates to true.2. List comprehensions kind of suck. [(a, b) for a in as for b in bs] is a cartesian product and not a zip? Really?
3. Loops don't help this either: There's no equivalent of the Lisp (loop for x in xs for y in ys do (stuff x y)). I have to explicitly loop over the index. This pisses me off.
4. I feel that I am generally shoehorned into creating and assigning more objects than I would like.
Honestly it seems kinda crippled in comparison to Lisp, which, by the way, runs faster.
I would go back to Perl if multidimensional arrays were not so godawful. Perhaps I should try Ruby.
> 2. List comprehensions kind of suck. [(a, b) for a in as for b in bs] is a cartesian product and not a zip? Really?
Strange. I would say it sucked if it was the other way round. You can use the `zip' function, if you want a zip.
zip (as, bs)
> 3. Loops don't help this either: There's no equivalent of the Lisp (loop for x in xs for y in ys do (stuff x y)). I have to explicitly loop over the index. This pisses me off.Try the function `enumerate' and `zip'. E.g.
for x,y in zip(xs, ys): stuff (x,y)
If you need an explicit index for your stuff: for (i, (x,y)) in zip(xs, ys): stuff (x,y)
> 4. I feel that I am generally shoehorned into creating and assigning more objects than I would like.I agree, only the other way around. Python is much too destructive and relies on in-place updating. E.g. recently we got `sorted' that doesn't sort in-place but return a sorted array --- but the `shuffle' function still works only in-place. Also dicts are destructive. There should be a persistent (i.e. non-ephemeral) data structure for key-value-mappings in the standard library.
http://docs.djangoproject.com/en/dev/intro/tutorial01/
Don't copy and paste the code in the tutorial and when they ask you to type something in the REPL, do it.
That's when it all started for me.
I'm disqualified to answer - as I come in your so called second type (softcore python lover perhaps), people who uses python to fix things in day to day life.
* It's the most concise, expressive language I know * Friendly syntax: I just write what I'm thinking and it pretty much works * Most importantly: It includes a ton of functional programming goodies (of which I make liberal use), but I can still just say x = 1 when I want to. Best of both worlds.
Unless, of course, Brainf*ck counts as a "scripting language". :D
It took me several goes to become friendly with Python. I find it excellent to try out algorithms. If I don't know how something is going to be best implemented, then writing a bunch of classes in Python and tweaking attributes and methods until the algorithm is as simple as can be helps me get there very fast.
The power of scripting languages really come down to a very simple thing: each line of code in a scripting language is equivalent to roughly 5 to 10 lines in a systems programming language. You're doing the same mundane programming tasks but with fewer lines and getting nearly the same performance as if you had written the code in one of the systems languages. It really won't make much difference which one you use, you'll see the same productivity gains using Perl, Ruby, Python, Lua or practically any of the others. However, the more obscure the language you choose, the fewer developers and the fewer available libraries to use.
I'm not against the non-Perl philosophy of There Is Only One Way To Do It, but for God's sake, don't insist on indentation! I am under a personal vow that until Python lifts its indentation requirement (say, via a command-line switch), I'm no way using this language for my programming needs.
If there was a command line switch, would you use it? Why?
It's also fun to spend an hour looking for a bug caused by somebody inserting a tab instead of a space somewhere. We had a production crash that took us a long time to fix because somebody hotfixed a file with the wrong editor and did this.
I also don't understand how forcing people to indent code in the same way magically makes people write good code. The kind of programmer that can't or won't indent his code properly is introducing bugs far more serious than bad layout into your project.
Python's a nice language in many ways but I consider the syntax to be a bug.
This. I'm convinced half the reason Ruby is displacing Python is that it's actually practical to talk about Ruby code in forums without ridiculous little-known workarounds like pastebins.
Hotfixing is a naturally perilous process regardless of language. I've spent hours tracking down untested hotfixes in Java.
You're also probably less likely to come across a badly formatted block of python code because that would generally result in a bug. Much like misplaced brackets in Java/C/C++ would result in a bug.
It doesn't make the code magically better. It makes it less redundant. Indentation should already be there, why do you need curly brackets?
The pain of keeping indentation correct is a forced ongoing investment in readability that is well worth it--at least to me.
I'm glad that haskell also has whitespace rules.
But in Python, you don't even have to worry about other people not indenting their code!
I guess the only complaint I might have is why bother thinking about indentation, ever? Throw in a couple of {} and now the tools can provide additional help.
When you edit Python, the tools can already help as much. The start of a block is obvious (def, if, for, etc), so tools indent for you. To dedent, just hit the right key (e.g. a backspace on an empty line in emacs) -- no harder than hitting the brace key.
And to the parent: I really hate to be "that guy", but can you give me an example where non-indented code looks better than indented code (since all your complaint really is about is style rather than what Python can help you do)? If it's just braces you're after, Python "supports" those by just commenting them out. When I first learned Python years back I was coming from a PHP and some Java background, and my code was sometimes single-space-indented, sometimes not indented at all, and it was hideous. After I realized I should be indenting anyway, Python made a lot of sense, all these languages with braces or 'end's everywhere didn't, and I can't think of any case I've ever thought "Man, I wish I didn't have to indent here." The one thing I can say I don't exactly like about Python now is the occasional self-hell.
Of course, most situations can be solved by a backslash-enter, and simple statements can be separated by ; but there are places where I wished for more flexibility.
This is only about readability, and overall Python code tends to be more readable than in other languages, although I've read beautifully written code in Java or Perl or C++, and the readability really depends a lot on the programmer writing it.
I think the major problem is the lack of focus in high-school / college on such things ... quite the contrary, many teachers are usually disconnected from real-world projects and don't have this skill themselves.
http://google-styleguide.googlecode.com/svn/trunk/pyguide.ht...
In fact at Google the maximum line length for python code is 80 characters because long lines make the code unreadable, and following the style guide basically anything can fit in a nice and readable way.
The only time I've had a problem with indentation is while copy-pasting things, occasionally that can get messed up and be annoying. Everything else is fine.
There are some interesting ideas regarding the use of whitespace in C here:
http://www.quinapalus.com/coding.html
I don't agree with everything he has to say- for example, I think his nested for loop example would be far nicer as something like this:
for(i=0;i<10;i++) {
for(j=0;j<10;j++) {
for(k=0;k<10;k++) {
printf("%d %d %d\n",i,j,k);
}
}
}
(Not to mention more in keeping with the principle of "alignment".) Still, if nonstandard indentation can make it easier to see the patterns in your code, it benefits both development and maintenance.for (i = 0; i < 1000; i++)
printf ("%d %d %d\n", i / 100, (i % 100) / 10, i % 10);
IMHO, such patterns (multiple nesting with empty outer loops), in most cases, are really an indication of just one real loop. Using multiple counters might also be an option.In case the loops are doing something different, they should be indented separately. For instance, the following makes little sense:
for (i = 0; i < 10; i++) {
foo (i);
for (j = 0; j < 10; j++) {
foo (i + j);
for (k = 0; k < 10; k++) {foo (i + j + k);
}
}
}
Of course I prefer Ruby, but that's a whole other can of worms :)
BTW in haskell whitespace is optional but nobody write code that way.
So if you don't have to learn Python right now, maybe you should first learn Lisp, Haskell, or whatever else you want or need to learn that isn't much like C/C++/Java. I think you'll have more fun this way. :-)
My personal experience is that the Java-ish languages encourage you to overthink problems a bit. Instead, I suggest that you just do what comes naturally. This will actually get you pretty far, as Python doesn't have that many gotchas (at least in comparison to Java or especially C++).
So what kind of programmer are you? What do you develop? These questions are essential before making any advise.
Secondly I don't mean to criticize Java. By calling it a toy language, I was simply referring to the fact that Java tends to make writing bad code difficult, and in doing this takes away some of the flexibility and power that you tend to associate with other languages.
I mean
while (str++) str = (str) + 1;
becomes
for (int i = 0; i < sb.length (); i++) sb.setCharAt (i, sb.charAt (i) + 1); // and relevant casting
While the above piece of Java code can be improved and condensed (for instance, by calling getChars and iterating through
them* and then creating a new String - would be slow however), I think you get the point.Tools are just tools. And I don't mean to come across as a jerk. I love developing. But that is as a means to an end, but not as an end in itself. - Those who like the latter, end up as research scholars; or Rubyists.
Try Ruby. It gives much more freedom than Python, not to mention countless way of shooting oneself in a foot (which you know already from the C family ;)
It's an aesthetic and personal choice.