Welcome to LjGww's Blog

Here we will see...

Tuesday, September 4, 2012

A year into languages

I am not much active here... huh. Well, it has been a productive period :) So, who would have a time to write texts when there is so much code to write :)

This year has been amazing for me so far. I have discovered so many new things and so many old things in a new way.

One fine day in spring I started discussing some project with a friend of mine. He has said - why not doing that in Python? As for coincidence a day or two before that suggestion I have pulled Python book from my library and started light reading - for no reason at all. Book was collecting dust for nearly 5 years when I was last time using it.

So things started rolling. Reading a bit about language, baby steps, try this, try that. After a while I have said lets now jump to web... I started with Django, got awed how that works, but was too away from what I needed.

Then I discovered webpy and all sorts of libraries for web notably markdown made a huge impression. Turbo gears too.

Then, I needed to switch to some databasing, actually adopting some old tables given in excell and making that data into database, so I lightly have taken sqlite on the road (amazing small database system)..

Quickly everything that I was doing in PERL once upon a time now have found a Pythonian approach. Python was flexible animal where ever I tried to go. In every domain I have found a bunch of libraries that worked extremely fine.

It was not a straight road but enjoyable one. I love when I make some results, i.e. when I do not run to a dead end that no one has experienced and no help can be found, and even after a lot of experiments you endup with no result - that is frustrating. Luckily that did not happen with Python at all. On contrary, Python proved to be THE TOOL for many little programming tasks. If you havent paid attention to it as yet, get to know it, it is worth spending time.

Not to stop at just one multifacet snake I also recently stepped on Go or better Go Language or how they call it short golang (to be easier to search).

Go was another refreshment and I am amazed that instead of propheting the scripts and object oriented approach Go actually takes a lot from Python in not tormenting a programmer. Syntax is shorter, target is well formed and what is most important it is open source!

In my view many commercial packages in software have huge disadvantage: company may go bust or thing may not prove profitable. I have seen that with microsoft many times but they are not only one to abandon something.

Open source is full of not often walked paths, but, somehow, if you wait long enough, paths congregate to some packages that live and live and after some time become so stable that are even better than many commercial software packages. I hope Go will follow this path.

There is a lot on the net that advocates or gives head start for Go. At this time I am not going to publish many links only start points, each link here is a tip of an iceberg...

If you are interested in Python start here http://www.python.org/
For Go start here http://golang.org/

Will try to come back here and write down some experiences with both of them, but a bit later, currently there is so many things I have to do.

Tuesday, January 17, 2012

Happy New Year with the old programming language with a brand new compiler

Ahh, windows dll's, 32bit programming, .net, inet, sockets...

Honestly, I find idea to use runtime libraries really fine programming approach. Once upon a time I have hit for the first time in my life a multiuser multitask multiprocess environment. With understanding of that environemnt issue of programming got a really new dimension to me. I was at that time using PC (in DOS at home and at work) and VAX computers (at work). VAX had runtime libraries. Limited memory (16Mb at that time was huge offer) was asking for some optimization. Vax had fortran, pascal and c compiler and basic interpreter. Quite fine programmers offer. Yet all of these languages (except basic) had approach - you write/compile a program and you get very small executable image - wow how efficient, but later I have realized by exploring system in more depth that all of these executables relied on Run-Time-Libraries. What was really neat on VAX is that it was smart on conserving memory. One copy of run time library for each language was almost always running on the system and all instances of programs in particular language were using it. Which basically means that each program had to reserve its own data memory section and compile calls to the library and some specifics of algorithm you are writing. And you could run many programs at once and even do some interaction between them.

At home situation was completely different. I had AT PC machine with dos (and 4dos if someone remembers that animal) and of course programmers miracle of that time which can do almost everything lighting fast - Turbo Pascal!!!

I have breath Pascal programming. It had a lot to offer compared to basic: compiling (basic was slow, computers were slow), variety of functions from abstract to direct hardware programming. You could virtually do anything you want and make it as efficient as it can be on contemporary hardware.

Of course, Turbo Pascal worked in smililar fashion as Vax Pascal with a slight difference. Run-time-library was still present but since DOS was single tasking RTL was glued to executable image. Luckily TP RTL was not large for what it had to offer. You cannot easily port code from Turbo Pascal to Vax forth and back. You needed to do some interventions in code. But it was as good as it gets.

After some time someone came with C and things have gone other way (C was appealing because it had shorther syntax and we programers are lazy to type). Yet, many years later using C, DB/clipper, and many languages, Turbo Pascal remained a niche tool. Whenever I needed to make something that would augment and fulfil some special programming need, Turbo Pascal proved to be handy. I made a ton of desktop publishing projects in Turbo Pascal working with textual files or calculating complex coefficient while calculating values of bonds and at that time rampant inflation rates. TP was versatile tool of choice. Period!

Then Pascal went to history... I moved to C++, ASP, VB, PERL, HTML, PHP, JavaScript, SQL ... yada... yada.. DOS changed to Windows, from VAX i moved to UNIX etc etc...

Recently, I negotiated to make a novel approach to some established system. Mathematical in nature, internet in background and limited in options, have specialized language that is just good enough that you cannot say its bad. After some research I have got the hint that you can extend that system with custom written .DLL. So lets explore DLL writing nowadays.

All of you that programm windows on a daily base know that Microsoft after many years of so called COM approach will sell its own grandmother to influence programmers not to use DLL's i.e. Component Object Model (COM) and make DLL hell on the way :). This goes to direction as you already know, of .net approach. Virtual machines :) installation blah blah..

In essence this is again not much different than vax, honestly I do not see much of a difference between RTL and VM's (virtual machines). In essence they are not far from each other. Your code is compiled in some meta-code and then that meta-code access ready made library to be executed. Is it RTL that is glued or dynamically linked or it is VM that is executing meta-code, I find that matter of taste.

But, for this project, I needed "ugly" 32bit DLL!!! And what's worse, I needed it to be compatibile with the system I am using. That system is REALLY PICKY how that dll shall be. I assumed it was written in C/C++ so it looks for standard COM DLL (c-ish like). So I took a ride of research which tool to use. Of course I could think nothing and write in C, but yet again WHICH C?

As it turns out, Microsoft was not a good solution as their all effort is on .net. All old Visual Studios are far out of fashion and support. Microsoft - dead end. Another option was open source C (in a form of GCC for example). I am not that familiar with alternative programming systems on windows that are not web based, applications are also developed in Java... every path that I have explored have lead me to some dead end. Can't use this because of that, this is not for that, you cannot do this in that, this is not intended to be used in this platform or in this way. Oh, Gosh... give me something that does not offer iPhone programming :) I WANT TO WRITE BLOODY UGLY COM DLL in WINDOWS 32!!!! :)

And then a short example of using Lazarus with this system i needed to extend - on some russian web site. Some months ago I was lightly researching pascal on mac, not out of need, but out of curiosity. Downloaded lazarus, tried to do something and then I was drawn to some other things. Life matters :)

So I made a test .dll in lazarus (downloaded one for windows), compiled, mounted dll in a system (wrote some additional interface code) and let it work. WOOOOOW! it worked where all others failed. And it worked STABLE. I left it working for a whole week, with all computer going to sleep and waking up. NO CRASH! I was awed.

Again, I was drawn away by other things I had to do in the meantime and started designing a new system that is mixture of dlls, socket connectors, management, calculations.... still yet on paper / drawing board but once i make all decisions code will unfurl. I have said let me make some socket examples ... some client some server and see maybe I will use web server maybe sql db maybe nothing of that at all, but lets go basic - make socket example.

Number of years ago I was writing some chat and some kind of remote controller in VB on windows sockets. It was frustrating, but it was fun in the same time, and at the end it was working fine. Socket (internet) programming shall be kinda separate programming course IMHO as much as web programming is.

What initially I did not realize that beneath Lazarus there was some strange animal that was taking many forms. Actually very soon I have realized that Lazarus on its own is not Pascal compiler (unlike Delphi and Turbo Pascal). Rather Lazarus lean on multifaceted animal called FPC or Free Pascal Compiler.

So I set to quest to explore it further. Then I really got awed!!! FPC was rare kind of animal that have enriched my programming world! FPC works on Windows, Linux, Mac, can write programs for iOS too, did not find anything for android as yet but do not take for granted that it would not support that too (like iOS, android is linux/unix derivate). Can Cross-Compile (compile for one platform on another one). Can mimic Turbo Pascal, Delphi, Objective Pascal, MAC Pascal... it can make code for MacClassic as much as it can make code for MacOSX both carbon and coccoa, of course it has strong Windows 32 and 64 bit support (looks very native to windows) and also do the same trick on Linux. Is it a time to go back to PASCAL? I think its worth exploring.

Oh yes, documentation is quirky, in some parts not explained in much detail, some examples may not be working, community seems not large and populated with game developers??? as it looks like. But do not forget some things. MacOS Classic is fully written in Pascal. Skype is written in Pascal. And this compiler is for at least 10 years on the road. Does not look too buggy! Some lab tests are required.

And oh yes two. I made small example of client and server working with sockets. Compiled, debugged on windows, until happy proof of concept, then I wandered what Mac will do, moved code to Mac, compiled on mac and made socket connection. Guess what? It worked. Not only that it worked, but the SAME SOURCE that I have compiled on windows, i compiled on Mac with NOT A SINGLE CHANGE, compiled the same like it was always on mac. And worked as it was written on mac. This I find really awesome! OK you may say its not the same when you write application with windows controls etc, this is simple console application, and Yes I will agree that when you wish to make some decent application you need to interact with user with windows and mouse, show some data, fonts and graphics, but if I can write at least 60% of code to be same between platforms I am already happy as puppy!

One more significant thing is that FPC is OPEN SOURCE!!!! You may have new official Pascal bangs and whistles from Borland called embracadero http://www.embarcadero.com/products/delphi but if you do not feel forking out many $$$ and you wish to have good pascal compiler that can do many things and do it well explore FPC Free Pascal Compiler ....

And yes, in a new year they have just released latest version 2.6.0. Even versioning looks convincing. Not to low not to high....

Some links where you can start from:

http://www.freepascal.org/download.var get compiler here
http://www.freepascal.org/docs.var equip yourself with PDF books/manuals here (html online manuals sometimes get handy too)
if you get confused ask questions here http://community.freepascal.org:10000/
Want IDE? get lazarus http://lazarus.freepascal.org/

that shall cover most of your bases. Cheers! Happy New Year!!!!