Search This Blog

Sunday, June 21, 2009

Creating a VB6+Python framework

Hi all, it's been a while since I wrote about framework on the Windows desktop. Now, I'll be sharing with you the framework that my friend and I are working on.
The inspiration was Django so we decided to try and pattern our framework in the hopes of achieving something that will simplify and speed up coding and eventually the software development process.

We tried out various approaches like using JSON to create a common data format. Oh by the way, what makes this framework unique is that we also intended it to make use of the Linux environment. Here's the plan:

The front end (the view and controller) would be developed on Windows using VB6. Why VB6? Cause VB.Net already has it's own framework and making another would simply be reinventing the wheel. Plus there are still a lot of developers using VB6 and it would be great to contribute something to this community.
Anyway, going back to the topic, the Linux participation would be utilizing the power of Python. Django was written in Python and we really appreciate how easy data handling was using it. So we thought of delegating this task (the model) to Python on Linux. Of course Python also works on Windows but we wanted to test it accross (Windows<->Linux).


I did mention JSON, and we thought it was a cool idea to use it as a model dictionary or how the data is described (what it contains, their data types, etc). No problem with it under Python.
Okay, comes the test on VB6. Since it's basically a JavaScript (ObjectNotation), then the first thing we need to accomplish is making javascript run under VB6.
Sounds like a really dead-end idea to most of us...yah I know, I got that impression too.

But hey, good thing there is the scripting library of VB6, I was able to evaluate and execute javascripts from within VB6. So now the problem is solved....or is it?

Unfortunately, my joy of having been able to run javascript on VB6 was shortlived. Parsing basic JSON objects and dictionaries was no problem, but the solution failed when we tried parsing the JSON array.
In javascript, the square brackets denote array content but it was returned as a string in VB6.
I thought we made a typo so what I did was create an HTML with javascript.

Hmmm...HTML? Aren't we discussing desktop framework here?

Yes, but I'm no expert in Java and I only know a little of javascript so I needed to test the JSON array using javascript as my only option. Okay, it turned out that the JSON array was correct in format, I was able to prove it using javascript on an HTML page.
So I deduced the problem was how VB6 scripting handles the JSON code. I hope I'm wrong but back when I was testing it, I can't make VB6 scripting understand the array notation.

Anyway, out of frustration we turned our attention to another approach, another data holder.
We thought first of XML, then we thought it would be more complicated compared to JSON and YAML. We then looked at Dictionary of VB6.
Okay it worked. But there are times when you don't need a "key" for your list so we tested the Collection data type. Now, it was very easy porting VB6 dictionary to Python, but it was a dead-end using Collection.
In VB6 no problem, but in order for Python to use it, it has to know the Object.ClassID.
For dictionary it would be "Scripting.Dictionary", but in Collection not that possible.
We used VB6's object viewer to find out where this collection resides in.
So we saw "VBA.Collection". Nice, we found it!
Python was having problems using it. So I tested it under VB6, simulating how Python would call it.

So instead of using:

Set ThisCol = new Collection

I tested it using

Set ThisCol = CreateObject("VBA.Collection")

And it didn't work!!!! Darn!!!
I had to Google a solution but there's none. I searched several forums and most of them also had the same problem and none has found a solution. Quite frustrating don't you think?

I'm using Windows, VB6, and then tried to use another Microsoft Product (the Collection), and it won't work. This is one of the reasons other developers are parting away from MS, product incompatibilities (when they are all under on parent company).
But I'm not here to rant about my frustrations, so I'll get back to my topic.

So we're stuck. No. We won't just give up on this one. We'll find a way to make something work, even if we reinvent some wheels.
A solution we saw on the internet was to create a wrapper for the collection so it can be used on Python (or any other language). It would work, but for me it was like a dirty solution.
I wasn't content with having used it just for the sake of making it work.

If we were to create such a wrapper then we make a good one to start with.
After hours of drawing on paper and several combinations of data structure, simulations and questions on how the new idea would work, we found an acceptable solution.

Yes we did, we we're able to use successfully and have progressed faster compared when we first approached this idea.

Next time, I'll discuss some of the things we did and maybe some progress we made. Thanks for viewing! See you next time.

Going dual

Sometimes, one is really not enough. In the case of blogging, one blog site won't cut it. So I made another blog which I made using Google App Engine, although it's more of a tutorial than a blog. But anyway, what I'm saying is I might not be able to update my blogs as often but I will definitely do.
I will also be working on a full time job next month so that would also cut off some of my time on the internet, but hopefully I can still keep up.

Here are my other sites in case you want to visit:

http://vegitz.appspot.com/
http://biznizcom.appspot.com/

Thanks

Sunday, June 14, 2009

Why still use VB6

Well, that depends on who you ask that question to. If you ask that to a VB6 programmer, you'll hear all the good things about the language. If you ask it from someone who hates VB6 then you'll hear all the bad things this language has and might even insult the programmers using it.

So without getting personal on the answer, how should we answer this question and every other similar questions?

The answer is "objectively".

Yes, I know there are still so many programmers that behave like martial artists of a certain school --- always claiming their school and style is the best and theirs can beat anything else.

But take note also that other programming languages suffer the same insult and discrimination simply because of this mentality. So let's list some of the bad and good that VB6 has, and not make judgments based on personal preference.

So what's bad about VB6?

B01 - it's not fully OOP compliant.
-----------------------------------
I guess it's because VB6 was not intended for OOP in the first place.

B02 - it's not strict when it comes to declarations and indentations
-------------------------------------------------------------------
Okay, true. VB6 allows you to use variable "X" without declaring it.
You can also put more than one statement in one line and it would still work as long the statements are valid.

B03 - it's slow
--------------
Yep, if you want speed go use C/C++. If you want to write a game, you won't have the speed that other games developed in C++ has. If you want to talk to a hardware, this has limited set of APIs but they are just wrappers and therefore slower compared to direct hardware calls like in assembly.

B04 - it's no longer supported by MS
--------------------------------------
True. You got a problem with your VB6 code, search the internet for forums that discuss VB6 or ask your peers that use it.

B05 - Anything else I might have missed.
------------------------------------------
I don't have a full list so I probably failed to mention other reasons.


And what's good about VB6?

G01 - three letters : RAD
--------------------------
Maybe not right now, but it was on top of the RAD ("Rapid" Application Development) programming languages for a long time.
There wasn't any other language that can create an application that fast and that easy like VB6.

G02 - it's simple to understand
--------------------------------
It should be since it was modeled after the BASIC generations (BASIC, BASICA, GWBasic, QBasic and TurboBasic). Its keywords were one of the (if not the) simplest. To print something it has the "print" statement. You want to display a message box or prompt to a user, use "msgbox".

G03 - it does the job
----------------------
Not all but a lot of applications and systems are built using VB6. These applications are used by large companies for handling production activities and transactions. Writing a similar application in another language would take more time.

G04 - it had a lot of support from other developers
----------------------------------------------------
Back when it was VB3.0 it already had some cool controls that you can just paste onto the form and use like the drive, folder and file list boxes. Since then, a lot of developers created custom controls to be used for VB, some were written in C/C++.
To a developer, this was great news as more technologies are available for use.

Well, this is how I would answer the question and any other similar questions. For me, there is no perfect language. Every one of the programming languages have their own strengths and weaknesses. Honestly it's pointless to try and pin point the best language, if I had to choose then I'd pick C++. Why? Cause as old as it is, it's still being used and is highly regarded in the IT world when you want to get something done.
Not only that, a lot other programming languages were developed using C++ (please correct me if I'm wrong but I believe Java and Python are some of the great languages that came out from C++). But as magnificent as it is, it still has some cons. One is that it will take considerable length of time to create a simple GUI application using it. Java is also a great language but you'll still hear some criticisms about it.

To me, these are all tools. Tools available to any developer. Why waste time debating what's the best? Why not just use the best at the moment or the best for a task? And why not combine these tools to create a better application? Why not strenghten a language's weaknesses instead of criticizing them?

And to answer the blog question, I say "why not?"

Desktop framework

We all know there are lots and lots of web frameworks out there like GoogleAppEngine, Django, RubyOnRails, CodeIgniter to name a few. They all help web developers to create web applications and/or web services in a shorter period of time (versus doing it the old fashioned way of coding every functionality). The very essence of either MVC (Model View Controller) or MVT (Model View Templates) is to separate the work and codes, thus making any web application reusable to other purposes other than what it's was originally intented to do.

For me, the best thing that this approach has is the "model" part. Why? Cause it simplified the database connectivity, and the business logic doesn't have to worry about SQL statements when retrieving and saving data.

Okay, enough of the web framework appraisal. If I am being paid for every instance I praise the MVC approach I'd probably be a millionaire by now.

So let's get to what I want to blog about --- desktop frameworks.

As far as I know (after Googling and asking peers), there is no similar framework in the desktop world. I could be wrong though, maybe there is but maybe that solution is not so hyped about unlike it's web counterparts.

Imagine if we have the same tool on the desktop world! We would only define a model for a certain application, a view layer (or Windows form if in MSWindows) , have a controller layer to facilitate between the view and model and that's it.

If you know any desktop framework, I'd really appreciate if you share it with us. Thanks!