Python Vs. The World


Blue Protoman

Well-Known Member
Joined
Mar 6, 2010
Messages
4,117
To avoid this thread going offtopic, let's talk about why Python is forgiving to beginners, or other things about it in general.


I'll start.


I myself am trying to learn it alongside C++/SDL, so when I get frustrated with one I can switch to the other and relax. Problem is, I've still been very busy lately, so I haven't done too much. I DID manage to solve a few problems in Project Euler in Python, though. It was bliss.
 
Last edited by a moderator:
Pythons strongest points are it's readable syntax and rich standard library. Overall, it's a well designed language without too many warts or strange exceptions. It's fairly small and therefore easy to learn. It has a fairly high level of abstraction and support for quite powerful constructs (e.g. higher order functions and closures).


On the other hand, I think that beginners will benefit greatly from learning a lower level of abstraction first. You develop a better understanding of the impact on performance by understanding what happens behind the screens. E.g. if you are allocating arrays and copying characters it's not so hard to see that "concatenating " + "strings together" + ", like in this example" + "is quadratic behaviour".


Also, static typing, as opposed to pythons dynamic typing (don't confuse this with weak vs strong typing), enforces a user to think about their types. This tends to result in better interface design and more robust designs then if all you've seen is dynamic typing (which more easily permits bad practices).


The downside of the lower level languages is that you tend to start with exercises like building data-types which other languages provide out-of-the-box. This makes it a more boring learning process as it takes longer before you start to see results.


I've programmed quite a bit of python the last couple of years, but I'm glad I started learning with C and Pascal.
 
I imagine it'd also be good for those who don't want to go into serious programming, eg those who just want to program Minecraft servers.
 
You consider writing servers to be non-serious programming? Distributed programs are a lot harder than you might think (though client/server is one of the easier models).


The general statement is true. If you just want to get some simple stuff automated and it's not your goal to become a great programmer, then languages like python are great to start with.


By the way, Minecraft is coded in Java.
 
One 'problem' I have in duck-typing languages is .. they (and Python is like this) have less 'documentation' right smack up front in the declaration, and polymorphism is generalyl done inside a function.


ie:


In Algol derived languages such as C++ and Jave and so on, you can do such tricks as..


int foo ( int )


int foo ( char * )


int foo ( int a, char b )


Just looking at the declaration 'helps' (though in python and lisp, you can use doc-strings of course, but doc-stgrings are often out of date, while a declaration must be more or less up to date); but more, I find it uglier in python to fake a polymorphic call..


in function foo, check for 'b' to be empty, and then assume we're doing the first or second invocation of foo; if b is populated, try the third. Just makes it a bit 'messy'.


for the first two invocations of foo, the python approach is to just try and perform and see how it goes before failing, but if you do have to do somethign differently by type, you really shoudl have another function (say), or multiple argument sets and have the coder react based on which arguments are supplied. Just feels 'ugly', though thats coming from a much more procedural background (I love lisp, but don't actually do much in it.)


That said, I really enjoy Python .. I just don't want to go back to uglier languages anymore, though I'm still a huge fan of C (heres to you Dennis Ritchie!)


--


I don't much like java for two main reasons..


-- 1) its verbose; I measure in C/C++ terms.. if a codebase is 1000 lines of C code, then it'd be 500 in python, and 2000 in java, in my books.


-- 2) due to (1) and the whole java community, eclipse, etc, people are raised to 'right click, generate' code in java, so you end up with _Monstrous_ number of classes and factories and nonsense that just complicates the actual design, and you need an IDE to decipher it. Dreadful. Single inheritence with 'interface' bullshit doesn't help .. just have real multiple inheritence like a man, as in python and C++ ;)


--


So python hits that spot for me .. its slower in runtime (though pypy and such are win!), but so comfortable to use, and so expressive, its very much the way to go, or fall back to C and C++ :)


jeff
 
The other case is where Java is taught as a 'first language', which is common at a lot of universities. Java's a fine language, but for an introductory student who has never programmed before, even a 'hello world' type program needs a lot of structure to it:



Code:
public class Hello

{

  public static void main(String[] args)

  {

   System.out.println("Hello, world.");

  }

}


So the instructor is obligated to say things like "Don't worry about classes yet. Or what public means. Or String[] args. We'll talk about all of that in the second month of the course.". It all just ends up being magic that students need in their code without understanding why. Some of the first things taught are how to assign values to variables. Or how to do arithmetic. And then some control with conditional statements and loops. You don't want all the extra clutter confusing students when you're trying to teach the fundamental (and language agnostic) concepts, which is why Python helps. So I've heard discussions where they'll teach Python as an introductory course, or start with Python and then introduce Java (or C# is becoming more common) later on.


And of course my disclaimer: I'm a Perl guy.
 
One 'problem' I have in duck-typing languages is .. they (and Python is like this) have less 'documentation' right smack up front in the declaration, and polymorphism is generalyl done inside a function.


ie: In Algol derived languages such as C++ and Jave and so on, you can do such tricks as..


int foo ( int )


int foo ( char * )


int foo ( int a, char b )


Just looking at the declaration 'helps' (though in python and lisp, you can use doc-strings of course, but doc-stgrings are often out of date, while a declaration must be more or less up to date); but more, I find it uglier in python to fake a polymorphic call..
This is true. It also becomes a lot harder for compilers to optimize the code.


Python 3 adds function annotations such that you can write:



Code:
def foo(x: int)-> int:


def foo(ch: str) -> int:


def foo(a: int, b: str) -> int:

However, they have no standard semantics. So you still need to use e.g. decorators to add semantics to it. Also, it doesn't do overloading out-of-the-box.



In python 2 you need to pass the types to the decorator itself to do something like this:



Code:
@overload(int, int)

def foo(x):


@overload(int, str)

def foo(x):


@overload(int, int, char)

def foo(a, :
[/CODE]

The decorator would need to implement a function registry and implement parameter type lookup to dispatch the proper implementation.


The downside of all this? It's non-standard, so code you encounter will rarely do this.

I don't much like java for two main reasons..


-- 1) its verbose; I measure in C/C++ terms.. if a codebase is 1000 lines of C code, then it'd be 500 in python, and 2000 in java, in my books.


-- 2) due to (1) and the whole java community, eclipse, etc, people are raised to 'right click, generate' code in java, so you end up with _Monstrous_ number of classes and factories and nonsense that just complicates the actual design, and you need an IDE to decipher it. Dreadful. Single inheritence with 'interface' bullshit doesn't help .. just have real multiple inheritence like a man, as in python and C++
I agree with this completely. Even simple stuff such as opening files requires tons of boilerplate code which is virtually always the same. The entire java community seems to embrace restrictive frameworks just to work around the shortcomings of the language.

The other case is where Java is taught as a 'first language', which is common at a lot of universities. Java's a fine language, but for an introductory student who has never programmed before, even a 'hello world' type program needs a lot of structure to it
There just is no proper way of doing Hello World in Java because of this issue. I vaguely recall a discussion in the python community about a PEP (python enhancement proposal) where the counter argument was that it would complicate hello world and thus was shot down :)


Regardless of which language is picked as a starting language, it really ought to be a procedural language or a language with an isolated procedural subset. You need to understand procedural programming for OO anyway.
 
I love Perl, but I can't write an essay about it. Really, it's a Swiss army chainsaw, from parsing/dumping some xml to relational DB to writing a daemon to run a countdown until the next episode of 'The Big Bang Theory' or hacking together a simple blog - there's a module at CPAN for it, just add some glue. :)
 
I love Perl, but I can't write an essay about it. Really, it's a Swiss army chainsaw, from parsing/dumping some xml to relational DB to writing a daemon to run a countdown until the next episode of 'The Big Bang Theory' or hacking together a simple blog - there's a module at CPAN for it, just add some glue. :)

Very true. I know people build games and the like with Python, and though it's probably possible in Perl, it wouldn't be the tool I reach for.


I've done a fair amount of systems work in the past, so I usually whip up some small scripts in Perl when Bash gets too unwieldy. And honestly, if I had picked up a Python book instead of a Perl book when I went to a library one day, I'd probably use Python for my scripting.
 
Last edited by a moderator:
You consider writing servers to be non-serious programming?

I meant adding functions or something. I assume you don't play the game? There are definitely things that could be done in Python, and at least one server in Classic Mode supports it. To be fair, I haven't checked out the scene in ages.
 
Python's a great "glue" language, as already mentioned. It has enough modules to be good enough for most general tasks, too. I hear you can embed C within it for when you need performance, too, so it's not a bad language.


The community and the PEPs, however... are dogmatic and tend to think that there's only one way to do things. That way of thinking is dangerous in programming, as there are many solutions. It's all about finding the one that fits the situation.
 
Python's a great "glue" language, as already mentioned. It has enough modules to be good enough for most general tasks, too. I hear you can embed C within it for when you need performance, too, so it's not a bad language.


The community and the PEPs, however... are dogmatic and tend to think that there's only one way to do things. That way of thinking is dangerous in programming, as there are many solutions. It's all about finding the one that fits the situation.

Um, I wouldn't call it dangerous. It's simply a design principle that they have in mind when they engineer the language.


It's like the Debian folks (I like Debian). They believe stability is king, therefore they'll have older versions of software and a slow release cycle. Some can easily say that's a bad thing, but for people who want extreme levels of stability, that's a good thing.


Same with Python. They want one way to do things.


The opposite example is Perl. Perl embraces the 'there should be many ways to do things', which gives people a lot of flexibly. However, this introduces new problems that Python doesn't suffer from (as much), mainly collaboration and code readability.


I'm not saying that Python is bad for having one way to do things, nor am I saying that Perl is bad for having many ways to do things. At the end of the day, there's no one right way to design a language (just ask the Ada folks over at the DOD); there's simply different design philosophies, and in the open source world, both philosophies tend to live and do well for their respective groups.
 
The community and the PEPs, however... are dogmatic and tend to think that there's only one way to do things. That way of thinking is dangerous in programming, as there are many solutions. It's all about finding the one that fits the situation.
The goal is to have one obvious way to do something. That simplifies the language for beginners and helps in readability. This does not mean that other solutions are automatically impossible.


I'm kinda curious, could you give an example of this where other solutions have become impossible due to this "dogmatic" thinking?
 
I didn't say it made other solutions _impossible_. I said their way of thinking was dogmatic. If there's one "obvious" way to do something, then most people won't bother to look for the other ways. Some of which might actually be more legible or operate more quickly.


It's dangerous because a programmer needs to be able to look at a problem from multiple perspectives. If the community acts against that by suggesting there's one right way to do things, what is that doing to fledgling programmers?


Again, I like the language. Just don't care for the community. That's optional, though. :)
 
It's dangerous because a programmer needs to be able to look at a problem from multiple perspectives. If the community acts against that by suggesting there's one right way to do things, what is that doing to fledgling programmers?

But any programmer worth their salt knows that one language isn't the answer to every problem, anyway. That's why my university teaches a Comparative Language course, so students can get a feel for the different types and uses of languages.


Language designers have a difficult time constructing a language because, at the end of the day, the best features of a language in general conflict with each other. It's just the way it is, and will (probably) always be. So they're obligated to narrow down their list of requirements, and Python went the way of 'readability' over 'you can do things lots of ways'. If they wanted to focus on many ways to do things over readability, they'd have Perl with wacky indenting.
 
It's dangerous because a programmer needs to be able to look at a problem from multiple perspectives. If the community acts against that by suggesting there's one right way to do things, what is that doing to fledgling programmers?
For me these "slogans" are rather abstract and seldom manifest themselves in actual code or even in design decisions. I've yet to encounter a problem caused by this, hence I was wondering if you had any clear examples of them.


It might be isolated to just a community interaction issue (e.g. hostility to non-pythonic code), I don't interact enough with the python community to be able to judge that.

If they wanted to focus on many ways to do things over readability, they'd have Perl with wacky indenting.
The only thing wacky about python's indenting is that you are obliged to do it. Let's be honest, you wouldn't want to write it without indenting anyway. It only causes problems if you post the code on some forum which eliminates the spaces or when you mix spaces and tabs (and the latter is easily fixed by any decent text editor).
 
The only thing wacky about python's indenting is that you are obliged to do it. Let's be honest, you wouldn't want to write it without indenting anyway. It only causes problems if you post the code on some forum which eliminates the spaces or when you mix spaces and tabs (and the latter is easily fixed by any decent text editor).

I completely agree. Python's just one of the few languages that enforce and use indenting, so I'm obligated to poke fun at it.
 
Back
Top