As some of you know, and most of you probably don't, my major is Computer Engineering. This means that I deal with very low level code 100% of the time, basically in pure C. This also means that I never get to experience the benefits of higher level languages, whether compiled or interpreted, statically or dynamically typed. As most of you should know, C is a compiled, statically typed language that's basically built for systems programming. This summer, as none of you would know, I will be doing an intern-ship at Sheepdog Inc, and will be up to my head in Python and Django software and code. What that means, is that I will have a lot more exposure to Python, and I thought I'd use the opportunity not only to learn as much as possible about this side of programming I am missing, but to also give tips etc. on whatever strikes me as interesting about the language. Obviously, I don't know the language perfectly, and am bound to make some errors along the way, or explain something the wrong way around. For that I ask you just leave a helpful comment and I can edit it and thank you =)
So, what is Python?
I realize I am a little late coming into python development, but here it goes anyway. Python is a dynamically typed, interpreted workhorse of a language. Dynamically typed should automatically trigger in your head that this is a very high level language.
Why should I care?
To me, there seems to be this separation between high and low level programmers. Low level languages are absolutely explicit. The programmer not only knows what type his variable is at all times, but also perhaps knows how many bytes wide it is. There is no such thing as a "Garbage collector" save the programmer themselves, and abstract objects like linked lists and stacks have to be created on the spot. Memory management cannot be taken for granted, and the goal of low level languages is to allow for efficiency from the aspect of the computer.
High level languages, on the other hand, allow for efficiency from the aspect of the programmer. It allows for an extra layer of abstraction between the programmer and the computer's hardware. More often than not, especially in the case of scripted languages, these programs (or scripts) can be easily moved from system to system, no matter what the operating system.
What I like about Python is that there seems to be one best way to do everything, instead of 7 or 8 equally good ways (though there usually is a 'best' way in any language, and I am sure there are entire books if not courses dedicated to this topic). I think this is a point where a lot of people decide that they do not like the language, because it almost reads like it disallows for flexibility. I disagree, because generally anything you want to do is already implemented, and you can just go ahead and do it. What's more, is that given that python is an object oriented language, you get the same sort of benefits you get from other OO languages like Java or C++, in a nice dynamic and interpreted atmosphere. It can be show, as it should be in future blog posts, that this level of abstraction, combined with an object oriented paradigm and dynamic type can lead to some very pleasing approaches to problems.
Diving in...
Those who read the popular web comic 'XKCD' may remember a particular comic in which a character explains the marvels of python, at one point stating that the hello world example was as simple as print "Hello, World!". Much to my regret, the module mentioned in the comic, expressed by import antigravity does not actually exist. Yet...
So, what's something simple we can start out with?
Well, we have at our fingertips an interpreted language. I am running version 2.7 on Windows, but basically anything I show you should be runnable for any other version of python 2 (though I recommend 2.7, as it is, I believe, the final version of python 2).
Let's do something basic, but a little better than that last example. Fire up the interpreter (IDLE or whatever else) or your favourite text editor (mine happens to be vim) and type the following. If you aren't using the interactive interpreter, save this as a .py file and run it with python myfile.py, replacing myfile as necessary, of course.
Still kind of trivial. What you should see after running this is "Hello, my name is Alex" printed onto the screen. Notice how we didn't need to tell the interpreter that mystr was a string or tell print what it was printing. For example, print 2 will print the number 2, and print mystr,2 will print mystr and 2 on the same line (with a space between them I believe).
Now, let's try something else. Let's split this line up into what we in the C world call tokens. Basically, we are going to create a list of items that represent each word in the above string. Then, lets print off each item in that list, each on a separate line. Dynamic types show themselves again:
As you can see, we don't need to know what each item's type is in order to make this for loop. What this ends up meaning is that we could take any list at all, of any type, and apply it to the same for loop. For example, lets say I have a list of integers.
What's more, what makes this actually useful is that we can stick such a for loop or anything else like it into a function and off we go, being able to apply any list we could possibly wish to it, for whatever our purpose. More on functions, and possibly classes, next time.
Happy Coding
~Bodom
So, what is Python?
I realize I am a little late coming into python development, but here it goes anyway. Python is a dynamically typed, interpreted workhorse of a language. Dynamically typed should automatically trigger in your head that this is a very high level language.
Why should I care?
To me, there seems to be this separation between high and low level programmers. Low level languages are absolutely explicit. The programmer not only knows what type his variable is at all times, but also perhaps knows how many bytes wide it is. There is no such thing as a "Garbage collector" save the programmer themselves, and abstract objects like linked lists and stacks have to be created on the spot. Memory management cannot be taken for granted, and the goal of low level languages is to allow for efficiency from the aspect of the computer.
High level languages, on the other hand, allow for efficiency from the aspect of the programmer. It allows for an extra layer of abstraction between the programmer and the computer's hardware. More often than not, especially in the case of scripted languages, these programs (or scripts) can be easily moved from system to system, no matter what the operating system.
What I like about Python is that there seems to be one best way to do everything, instead of 7 or 8 equally good ways (though there usually is a 'best' way in any language, and I am sure there are entire books if not courses dedicated to this topic). I think this is a point where a lot of people decide that they do not like the language, because it almost reads like it disallows for flexibility. I disagree, because generally anything you want to do is already implemented, and you can just go ahead and do it. What's more, is that given that python is an object oriented language, you get the same sort of benefits you get from other OO languages like Java or C++, in a nice dynamic and interpreted atmosphere. It can be show, as it should be in future blog posts, that this level of abstraction, combined with an object oriented paradigm and dynamic type can lead to some very pleasing approaches to problems.
Diving in...
Those who read the popular web comic 'XKCD' may remember a particular comic in which a character explains the marvels of python, at one point stating that the hello world example was as simple as print "Hello, World!". Much to my regret, the module mentioned in the comic, expressed by import antigravity does not actually exist. Yet...
So, what's something simple we can start out with?
Well, we have at our fingertips an interpreted language. I am running version 2.7 on Windows, but basically anything I show you should be runnable for any other version of python 2 (though I recommend 2.7, as it is, I believe, the final version of python 2).
Let's do something basic, but a little better than that last example. Fire up the interpreter (IDLE or whatever else) or your favourite text editor (mine happens to be vim) and type the following. If you aren't using the interactive interpreter, save this as a .py file and run it with python myfile.py, replacing myfile as necessary, of course.
mystr = "Hello, my name is Alex" print mystr
Still kind of trivial. What you should see after running this is "Hello, my name is Alex" printed onto the screen. Notice how we didn't need to tell the interpreter that mystr was a string or tell print what it was printing. For example, print 2 will print the number 2, and print mystr,2 will print mystr and 2 on the same line (with a space between them I believe).
Now, let's try something else. Let's split this line up into what we in the C world call tokens. Basically, we are going to create a list of items that represent each word in the above string. Then, lets print off each item in that list, each on a separate line. Dynamic types show themselves again:
mystr = "Hello, my name is Alex"
print mystr
mylist = mystr.split(' ')
for item in mylist:
print item
As you can see, we don't need to know what each item's type is in order to make this for loop. What this ends up meaning is that we could take any list at all, of any type, and apply it to the same for loop. For example, lets say I have a list of integers.
mylist = [1,2,3,4,5]
for item in mylist:
print item
What's more, what makes this actually useful is that we can stick such a for loop or anything else like it into a function and off we go, being able to apply any list we could possibly wish to it, for whatever our purpose. More on functions, and possibly classes, next time.
Happy Coding
~Bodom
2 Comments On This Entry
Page 1 of 1
demosthenes2k8
25 April 2011 - 05:12 AM
I'm just going to leave this here...
This was a pretty fun look at Python, I can't see what you write about some of the other features!
This was a pretty fun look at Python, I can't see what you write about some of the other features!
Page 1 of 1
← January 2022 →
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 |
| 9 | 10 | 11 | 12 | 13 | 14 | 15 |
| 16 | 17 | 18 | 19 | 20 | 21 | 22 |
| 23 | 24 | 25 | 26 | 27 | 28 | 29 |
| 30 | 31 |
Tags
- Adminsitration
- Apple
- assembly
- atmel
- AVR
- avr-libc
- Bada
- beginner
- Blackberry
- boot
- C
- C#, .NET, and XNA
- C++
- ccleaner
- code
- defragmentation
- Desktop
- dynamic
- embedded
- FooBada
- foobar
- foobar2000
- Gnome
- high
- interrupts
- Java
- level
- Linux
- Math
- Matricies
- Matrix
- microcontroller
- nasm
- New
- Open Source
- Operating System
- Oracle
- oscilloscope
- Programming
- Python
- Random Computer Stuff
- Random Rants
- Repair
- Samsung
- sector
- serial
- speed
- Square
- static
- timer
- UART
- Ubuntu
- unix
- USART
- virtualbox
- Visual
- VOIP
- Windows
- Windows 7
- x86
My Blog Links
Recent Entries
-
Playing in Pythonon Apr 24 2011 10:06 PM
-
-
Using Virtualbox as a bootloader testing environmenton Nov 13 2010 11:00 PM
-
AVR Oscilloscope, Part 1on Sep 13 2010 07:21 PM
-
My thoughts on Bada as an Operating System and as a Development Platformon Sep 05 2010 10:43 AM
Recent Comments
Search My Blog
12 user(s) viewing
12 Guests
0 member(s)
0 anonymous member(s)
0 member(s)
0 anonymous member(s)



2 Comments









|