Many years ago I've decided it was time to pick up a modern programming language. In the past I had written lots of (Turbo) Pascal code, some x86 (and more exotic) Assembler and a bit of C, but then for several years I only did shell/awk scripts and ported C software to IRIX and SINIX/RU. So I sat down and decided to find a nice general-purpose language that I would focus on learning. I wasn't quite sure what for yet…
Why Python is Important for You
211–220 of 231 posts
Re: Why Python is Important for You
#212Earlier quoted context omitted.
500K LOC in Python is what, 2.5M->5M in a statically typed language? At that size I would expect any project to require explicit convention and communication management, simply because no one person can hold the whole thing in their mind at a resolution that reveals the code's meaningful features.
And it's probably 200k lines in Haskell, which is very statically typed :) (For reference, GHC--a very complicated compiler with clever optimizations, language extensions, multiple backends...etc--is something like 125k lines of Haskell.) I've spent a significant amount of time with Python, both at work and in my classes and yet my Haskell code is usually 2-3x shorter for very similar programs. I think it's also easi…
http://shootout.alioth.debian.org/u64/benchmark.php?test=all...
I know most programs there are written in an unusual way, but that at least means something.
Re: Why Python is Important for You
#213I like to call this cognitive compatibility - the amount of effort required from an uninitiated English-speaking observer to understand what a program does. Most people who are deeply familiar with a language will have a tendency to discount this effort, but really it is essential because it minimizes the translation layer that your brain has to use any time you read code. Python encourages code which is readable in…
Re: Why Python is Important for You
#214Earlier quoted context omitted.
I wasn't aware that Python and JavaScript were in competition. Or for that matter, that JS is by any stretch of the imagination "invested in performance". People don't use Python because of its merits as a programming language. They use it because of the excellent standard library, Scipy, Sage, etc. While it may be that in a decade JavaScript has built an ecosystem to match, I frankly don't see why anybody would both…
> non-web developers Sorry, not sure what that means OK maybe not everything will be a web app, but pretty much everything that isn't some deep driver-level boot code or embedded firmware is already almost always part of some sort of web app, and the stuff that isn't is pretty much all written in C/C++. When is the last time you wrote a Python program that didn't interact over TCP or equivalent with some other proces…
> When is the last time you wrote a Python program that
> didn't interact over TCP or equivalent with some other
> process?
My last python program was a set of scripts to help me analyze music harmony. Entirely CLI based.Before that? objcfix - a refactoring tool. Again, CLI based.
That's not counting the multitude of small scripts I write on a day to day basis. I've written a large amount of Python code, and very little of it interacts with a network.
Put it this way: Python was invented in 1991, the same time as the web. It didn't become a good tool for making websites until after 2005 when Django arrived. So, what did people do with it before then, if not make websites?
> but pretty much everything that isn't some deep driver-
> level boot code or embedded firmware is already almost
> always part of some sort of web app, and the stuff that
> isn't is pretty much all written in C/C++.
This is not the reality we live in. There's:* Games (either written in C++, Objective-C or Java nowadays, plus a bit of Lua)
* Big Software: MS Office, Photoshop, Avid, Logic, InDesign, etc. Written in C++
* Scientific Computing: Written in C++, Matlab, Mathematica, Python
* Financial Computing: C, C++, Java, and a tiny spot of OCaml.
* iPhone/Android Apps: again, Objective-C or Java.
* "Enterprise Software", whatever that is. Java.
And as you point out, embedded software. Everything around us runs Embedded C.
The future is the same as the present: full of a rich and diverse selection of languages.
Re: Why Python is Important for You
#215I have a list I wrote up once about Python's problems. Some of these are more exotic than others. Most of them are kludgearoundable. A couple are fixed in Python 3. Some are simply design choices that are exactly different from my mental model of the world, and due to the TOOWTDI Python world, it is frustrating to work with them. Some Things Wrong With Python * Immutable strings[0] * Everything a reference[1] * Envir…
You think immutable strings is a bad thing?
Re: Why Python is Important for You
#216Earlier quoted context omitted.
Did you give JRuby a try?
I didn't. Perhaps I should, but it seemed like it would have to be at least 10x faster than YARV to be worth it, which looking at the benchmarks seemed unlikely (but who knows? maybe I was hitting some sort of interpreter specific bottleneck)
Re: Why Python is Important for You
#217As a commenter on the article wrote: what about Ruby? I say this as a happy Python user. Ruby seems very similar but I'm reminded of a pg essay on language power: looking up the power curve, you see '$Language plus a bit of weird stuff that is probably irrelevant.' So I don't trust myself. As someone who loves Python and doesn't know any Ruby beyond a few bits of syntax and the obvious bits that are common to most la…
I used Python for a really long time and switched to Ruby several months ago. Benefits of Ruby are: -no distinction between expression and statement (everything has a value) -lambdas can thus contain any expression -much bigger range of built-in methods and classes (all permutations of a list, removing duplicates from a list, Rational class, Regexp class, Range class, etc.) -more flexible syntax and "control operator…
I got into Ruby by pure accident (No Rails-bait). I needed a scripting language to automate some tasks and one of my friends was playing with it back then and suggested it.
Ruby's weakness (and it's strength at the same time) is that it got popularized by Rails. As a result a huge community has grown around it - but it brought a tunnel vision effect along with it. People don't recognize that there are things besides Rails and it's reflected in weak (non web-dev) library support.
I didn't like the fact that there's a big push in Ruby-land for metaprogramming / DSLs and monkey patching. Ruby's not inherently that great at it. It just happens that you can do it, but it doesn't mean you should. Which has always been in my eyes mostly a big abuse of *_eval, method_missing etc. that leads to performance issues, maintainability issues, and so on. All that just to save a few keystrokes. Couple that with the very implicit nature of Ruby then you get a disaster. How often did I want to use libraries that turned out to be monkey-patching the same built-in classes and clashing with each other, How often did I want to delve to some code base to customize something, make a fix, etc. just to find such coding practices and being unable to reason about it in a regular object oriented fashion which Ruby's foundations are built on.
The more I wanted to build serious things in Ruby the more often I would hit such problems.
This all brings a question: What would happen if Rails had disappeared the next day. What would all these people do? What could they use instead?
It was an obvious choice not to stick with Ruby because it has nothing to offer in the long term over Python. Learning python is a very good investment - I can do web programming, gui programming, scientific computing. I can use it to script blender, gimp, you name it. And unlike Ruby - I have excellent alternatives for each task.
Re: Why Python is Important for You
#218Earlier quoted context omitted.
I find a great way to avoid deep nesting is to move code to functions, and bail out when some conditions are not met. As an example, this deeply nested code: def frob(someargs): if something > 2: ... # do some processing if that == "CONNECT": ... # some more processing if verdict in blessedsolutions: ... # even more processing print "Happy birthday!" I tend to write like this: def frob(someargs): if something I do th…
An less-known technique to dealing with nested-ifs is through the use of an one-time loop. Here's an example (in JavaScript): function oneTimeLoopMethod(x) { var result, temp = -1, a, b; do { ... extra processing code ... a = func_a(x); if (!a) break; ... extra processing code ... b = func_b(a); if (!b) break; ... extra processing code ... temp = b; } while (false); result = postProcess1(postProcess2(postProcess3(tem…
Re: Why Python is Important for You
#219I have a list I wrote up once about Python's problems. Some of these are more exotic than others. Most of them are kludgearoundable. A couple are fixed in Python 3. Some are simply design choices that are exactly different from my mental model of the world, and due to the TOOWTDI Python world, it is frustrating to work with them. Some Things Wrong With Python * Immutable strings[0] * Everything a reference[1] * Envir…
You forgot mutable default arguments! def fn(ls=[]): ls += [1] return len(ls) (My syntax might be a little off, but you get the idea.) This will return an ever-increasing number if called repeatedly with no arguments. Also, the reliance on tuples, particularly tuples of one item always gets me because (1) and (1,) are different. Also, the scoping for list comprehensions doesn't make sense: x = 11 [x for x in [1,2,3]]…
Re: Why Python is Important for You
#220As a commenter on the article wrote: what about Ruby? I say this as a happy Python user. Ruby seems very similar but I'm reminded of a pg essay on language power: looking up the power curve, you see '$Language plus a bit of weird stuff that is probably irrelevant.' So I don't trust myself. As someone who loves Python and doesn't know any Ruby beyond a few bits of syntax and the obvious bits that are common to most la…
As a Python user, I'll give my personal reason for using Python over Ruby. Upfront: I think Ruby is absolutely fantastic. It's a very elegant language. In a lot of ways I think it's cleaner than python. I'd love to use it. Except... Every interpreter I've tried is just too slow. I recently ported over a networking library I wrote in python to ruby, and the requests per second (CPU limited in this case, since it was t…