Is Django the way to go for a newbie?

Chris Angelico rosuav at gmail.com
Mon Aug 10 03:27:49 CEST 2015


On Mon, Aug 10, 2015 at 3:41 AM, Michael Torrie <torriem at gmail.com> wrote:
> Web development is very a very hard problem, largely because it involves
> quite a few different domain-specific languages that you have to be
> proficient in...
>
> In this area, node.js is getting very popular. I don't care much for
> javascript but using it on the server as well as the web browser itself
> reduced the number of languages you have to know by one.

There's another thing you absolutely have to know when you do web
development, and that's i18n. This is why I don't recommend Node.js
for server-side work - because Python's Unicode support is better than
JS's. Stick with Python (and avoid Python 2 on Windows) and you get
great Unicode support. Do anything in JavaScript/ECMAScript and you
get UTF-16 as the official representation. What's the length of the
string "Hello, world"?

>>> len("Hello, world")
12

> "Hello, world".length
12

So far, so good. What if those weren't ASCII characters?

>>> len("🄷🄴🄻🄻🄾, 🅆🄾🅁🄻🄳")
12

(That's Python 3. In Python 2, you'd need to put a u"" prefix on the
string, but it's otherwise the same, modulo the Windows narrow-build
issue.)

> "🄷🄴🄻🄻🄾, 🅆🄾🅁🄻🄳".length
22

ECMAScript stipulates that strings are not codepoints, but UTF-16 code
units, so whenever you work with astral characters (which includes a
lot of emoticons, Chinese characters, and other symbols that your end
users *will* use), they'll get things wrong. The length of the string
counts astral characters twice; indexing/slicing can take half of a
character; any manipulation at all could corrupt your data.

So, use Python for all your text processing. Life's better that way.

ChrisA


More information about the Python-list mailing list