28.10.09

Simple Introduction to Python for C/C++/Java Developers

Permalink 15:16:43, Kategorien: Hauptkategorie  

During my work, from time to time, I have to use different new programming languages. Actually, I’ve seen a lot. I started with Basic, then Pascal, C++, C, Assembler and then Java. I still use some of them for various application such as Basic (for Excel Macros), C++ for high-performance desktop applications, C for embedded applications and Java for both desktop and embedded software development.

Recently, I added Perl to my repertoire. You can quickly produce powerful applications…that no one else but you can ever read or understand. this is due to perls “flexible” syntax. You can use print("Hello") or print "Hello" or mix it up. I descided to code that way like I was doing it in C and it worked quite well for me and everything was very readable. And I was still able to quickly write programs to parse and write XML files, log files etc. That was really great and easy.

Alltogether, it was something different but I could understand it.

Why I first saw a Python script, I though “what the hell is this"? where does the main program starts? What is def and where have all the parentheses gone? I have to admit, that this script was a very long complicated script because I actually didn’t want to learn Python but to understand what the script does.

After this first glance I was scared and didn’t touch Python for a while. :no: Plus, I was deeply ashamed because I read that Pythod was inteded to act as an “easy-to-learn” language. And then comes *me* who can’t understand basic concepts! :oops:

But recently, I had to do some other work where Python was involved. So I continued my expedition to the Python pole. And hell yeah, it was cold ;)

I don’t know about you, but the most important thing to learn (and it took me a long time to find out my self), was:
Python uses INDENTATION to define blocks. Yes, indentation! No parenthesis, no visible characters at all! Only tabs or spaces. And thats the next thing: def. def actually defines a new function. How does both work? Take a look at the following snippet:

Code:

def hello():
    print "Hello"
hello()

Line 1 defines a function with no arguments called hello. the next line does what it says, it prints out the string "Hello". What’s important is the indentation (as explained before). I used one tab. The python interpreter recognizes it and assigns this code to the function. The last line is a function call to the function we have just created. this line is not indented and thus does not belong to the function but to the main program!

To sum this up:

  • Indentation istead of parentheses
  • No semicolons at the and of a line necessary. Every line is one expression unless you specifically tell the interpreter to

These are some very basic but important things to know.

Ok, one thing thats also different from languages like C or Java is that you don’t need to declare variables. You just introduce them whenever you need them:

Code:

#Oh, we need an integer...
i = 3
print i

That works,because of the way the Python interpreter is designed. I have ported a Python from C to Java, so I know about the basic concepts which I like very much.

Eventhough, we just saw a function, python does not really treat a function as a C compiler would do. Python is completely object-oriented. Internally everything is an object.

(The next part is very technical, but helpful to understand how python works.)

  • You create a new scrip file? It’s a module object!
  • You create a function? It’s Function object!
  • You write the function code? It’s a Code object

And so on…

One basic concept of Python is the Attribute. Every class in python has a list of attributes, called dict(ionary) (like a hash table). Now, according to the example above, let’s say its in a file called PythonTest.py, then a new module object willl be created and stored in the global attributes dict with the name “PythonTest” as the key and the module object as the value. Because of the def expression, a new function object will be created. It will be stored under the key “hello” int the modules dict. The code within the function will be stored as it’s code object. Every executable object (like function or a module can have a code object). the last this is the function call in line 3. The is part of the code object that will be stored in the module.

The memory look a bit like this:

Interpreter global attributes
- “PythonTest” : Module Object A

Module Object A
- “hello” : Function Object A
- Code Object

Function Object A
- Code Object

If this script gets executed, the code object of the module will be interpreted. It tries to find the key “hello", in either the gobals dict or the modules dict where it will be found. Because of the parentheses, the compiler knows that this attribute should be executed and the functions code object will be interpreted. Finally, the print statement gets executed.

E.g., if you would have defines the integer i (as in the above example) within the function “hello", a new attribute "i":Integer(3) would have been created.

You can alway create, modify, and delete attribute no matter if its plain variables or even code.

Ok, the second basic concept is constants. Constants belong to a class, as well, and are stored in a List (like a array) referenced by numbers assigned by the compiler. that’s wher the string “Hello” and the number “3″ is stored. At run-time, the interpreter loads and stores such consts if needed and passes them to functions and stores them in attributes where the can be modified.

Ok, this was more than I planned to write, but I think this post descibed both some very basic parts for brain-dead people like me and on top of that, the internal concept of Python.

15.10.09

Thoughts on the iPhone

Permalink 14:53:29, Kategorien: Hauptkategorie  

Here are some thoughts on the iPhone :)

I know this topic is higly polarized and there are a lot of people screaming “The iPhone is bad, apple is worse and their buisiness policy is far the worst". Other people, often characterized as Apple fan boys, love everything about Apple do not tolerate any criticism by saying “either you love it or don’t use it". I try to be as objective as objective as possible but it is still influenced by things that are important to me. For sure, there are a lot of people whit other opinions. So this is just my view on the whole thing.

And this is “My mobile history” (Skip it if you’re not interested in my reason to buy the iPhone):

My fist phone was a Motorola “phone booth". The handling was quite horrible. Then I used a number of Nokia phones until I started with some HTC Windows Mobile powered phones. Eventhough the handling was almost as horrible as my motorola, I loved it because of the touch screen.
It made a lot of things easier:

  • Choosing menu options (no more item by item clicking)
  • Copy and paste (No options menu necessaray)
  • unecessary options were hidden in a context menu
  • browsing was a lot more comfortable (as long as you don’t use the mobile Internet Explorer).

But still, the whole visual feedback and all GUI stuff had a lot of latency which made myself want to tear out my hair sometimes.

After the first iPhone was realeased, WM developers and phone manufactorers got nervous and started to wrap WM in a pretty looking interface which was, most of time, slower than the WM interface. That, I installed a new ROM (thanks to xda-developers) to improve speed and memory usage because windows took the biggest part of the RAM which made it impossible to store and run more than a few applications on the internal flash.
This interface also tried to implement a iPhonish scrolling behaviour which failed miserably. from this point on, I was looking for a new phone. And I was looking for any phone except the iPhone because:

  • the iPhone, despite everything liked, was much too expensive for the features it has and, it did not have Copy and Past which I used quite often on my WM phone.
  • So I was looking at HTC but there was no real alternative. The Google G1 phone was expensive as well and was extremely ugly with that skew surface and on top of that, I don’t like any kinds of movable phone bodies like sliders etc.
  • Ok, that I took a look on Blackberry but the phone housing was bad quality.
  • The Samsung Blackberry-style phone had nice interfaces (Full qwerty keyboard, trackball and touch screen) but also Windows Mobile.
  • The Nokia E71 which has a nice metal housing, good keyboard and is very slim but no touch screen.
  • Then I heard about the Kogan Agore Android phone for unbelievable ~250€ with touchscreen and keyboard. I preordered that phone and two month later I got a refund and an email saying it’s being delayed.

So, at the end, there was no phone left that would fit my needs except the iPhone which was released as 3GS at that time. Now, that I was searching for a decent phone for over months I decided to eventually buy the iPhone. It took me 650€ and a friend in Italy to get the 3GS 16GB.

The iPhone:
I chose to buy the black version because a freind showed me his white 3G which got a lot of tiny crack arounf the connector which were clearly visible. Additionally, the white case and its edges took the color of his blue jeans. So, eventhough white looks better when it’s new, the black case “gives you happiness long time” ;)

The key feature which also made me buy it is the interface. Especially with the 3G*S*, everything is fluent, no latency when do perform any menu action. On thing, that many people might rate as “unnecessary gimmick", is the visual feedback. if you scroll to far, the screen follows you finger as if it’s tied with a rubber band. That really makes the difference. This is quite important because you always know when a screen is at the end. In WM, sometimes the system hangs and you always have to double check if you reached the end or it’s simply the system slowing down. In contrast to WM, where often my blood preasure was close to “heart attack", I simply classify the iPhones interface as:

Everything works as expected

This sounds like a simple requirement but theres not 1 touch based phone that would deserve that rating. And I tried a lot ;) This is simple and I wonder why there is no manufactorer that can build a phone sofware that fulfills that basic requirement. But I guess it’s technically more complicated to implement as it seems.

I know this has been mentioned a million times before, but the browser is really a dream to use. No other phone (including Android) has that intuitive and fluent interface. It just make a lot of fun to scroll by flipping and to zoom with two-fingered multi touch guestures.

In general, thre’s not much I don’t like.

But one thing is the App Store. At first glance it’s very nice. You can search it, download it, a lot of free App. But still, it’s a private party. You’re only allowed to enter if you’re really nice to your host Miss Apple, give her some money and hope that she won’t find anything that could make lose money.

I wanted to start develop a software for private use only. But that’s not possible. You can downlows all tools, IDE, and iPhone emulator for free. You can develop software, run it on the emulator for free. But you’re not allowed to put it on you OWN phone!!! YOU CAN NOT RUN YOUR OWN APPLICATION ON YOUR OWN PHONE!!! That’s really a pain in the ass. You need to apply at Apple hope that they allow you after few weeks to transfer 100 bucks to apple. And then, you get a certificate that allows you to run your application on your phone. Ok, now, you can also put your App in the App Store for free, but what if you don’t want that? But if you want, again it you frendly party host who descides if your App will be added to the store. The good thing on open platforms is, that you get a lot of nice little apps that can help you whith a lot of things for free. But what Apple does is keeping all these nice little programs away because either the developers don’t want to pay or because the app does not comply with Apply mysterious rules that they never really communicated to the world. You are not able to use a check list to check you own program. They only say: Don’t harm the system, don’re reproduce anything that’s already on the phone, blablabla…

That is really something I don’t like.

OK, I think I will stop here because I could go on for hours ;)

Introduction

Permalink 11:29:59, Kategorien: Hauptkategorie  

Hi!

Very often, I think about some topics I might share with other people or some problem I have and I want to publish my solution because it could help other people. Very often, I can find help on other people’s websites and blogs who share their knowledge. Now, I try to give something back!

Any comment are appreciated - except spam :)

Jan

Mai 2012
Mo Di Mi Do Fr Sa So
 << <   > >>
  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      

Suche

User tools

powered by b2evolution free blog software