4 ms·
Ruby and Python syntax are quite different. Ruby syntax seems designed to be difficult to learn. It uses obtuse, non-standard, irregular syntax for common ope
by csense 13y ago
Ruby and Python syntax are quite different. Ruby syntax seems designed to be difficult to learn. It uses obtuse, non-standard, irregular syntax for common operations, requiring constant consultation of the manual for the beginner to see any non-trivial program as anything other than line noise. For reasons I do not really understand, Ruby is quite popular with HN users and I may actually receive downvotes for what I've said so far.
Python's syntax, by contrast, is simple, intuitive, and fairly standard. Python does have a few innovations over other languages -- the most important that come to mind are indentation-delimited blocks [1], tuple unpacking, list comprehensions, generators, args/kwargs, and access operator overloading. All of these are usually optional in your own code and easy to grok when you seem in others' code. When you are ready to use these syntax elements, you will find them easy to learn and quite practical in a variety of situations.
Python code can be concise without being unreadable. This greatly improves developer productivity, which is very important. Most projects are bottlenecked by developer time.
Python is a truly general purpose programming language, with excellent library support. People can and do use it for command-line utilities, web applications [2], math/science [3], and desktop applications [4].
[1] Using indentation to delimit blocks is a controversial "innovation" of Python. I suggest suspending judgment until you've written at least one medium-sized program in Python. As a matter of coding style, usually programs written in high-level languages also use indentation to denote blocks; when this indentation gets out of sync with the rules the language actually uses to delimit blocks, you can get hard-to-spot bugs like this one:
if (myflag);
myFunction();
This will compile, but the if statement is a no-op, and myFunction() will always be called, which is probably not what the author intended. The above bug cannot happen in Python; since Python actually uses indentation to determine blocks, by definition the indentation cannot get out of sync with the way the compiler/interpreter sees your code.
[2] For Python webapp development, I recommend writing a simple webapp with Flask first, then adding sqlalchemy for proper database support. Once you're comfortable with that combination, you'll want to switch to Django.
[3] Try Sage, IPython, numpy, and scipy.
[4] I recommend GTK+ for desktop apps, especially on Linux. http://python-gtk-3-tutorial.readthedocs.org/ http://python-gtk-3-tutorial.readthedocs.org/
- mattkrea 13y agoI spent some time with Python just this morning and was curious. Starting out.. should I use Python 3 or 2.x because most packages / modules are written for 2?
- csense 13y ago> most packages / modules are written for 2 This is actually not so much the case any more; many packages now support Python 3, and Python 2.7 is nearing end-of-life. However, many of the tutorials you will read have probably not updated their statements about Python 2/3 compatibility. Python 2.x was indeed far better as far as library compatibility for quite some time after the (IMHO idiotic) decision not to use the proven Python way to introduce new features (from __future__ import), and instead have the 3.x release break backwards compatibility entirely. My advice is to start with Python 3, then switch to Python 2 if you discover your project requires a specific library that does not yet support Python 3.
- jaegerpicker 13y agoPython is a fantastic eco system and it can be used for a HUGE variety of tasks with really great results. Certain problem domains are better tackled from 3 and some from 2.7. Web development (my day job is writing python for a series of django webapps) is a great experience with either. I think scientific and data science based environments have better lib support in 2.7.