Wednesday, May 29, 2013

Less Frame, More Work

When I started to code QetriX in PHP, I didn’t plan to release it as a framework. But with progress of the concept my perspective slightly changed.

First of all, the idea is cross platform, cross environment and cross language. It says just “what”, not “how”. Second of all, I think the idea may be used in a wrong way, so It’s gonna be better, if I set the rules here and let fellow programmers just to follow them and stick with them.

Because all languages I’m focusing on are very similar, I decided to unify the code across all these langs. I’m talking about PHP, Java and C# here.

How it works:

  • Install
  • Profit

I don’t plan to document the framework to the core. I don’t want people to mess with the core code. One day I may release a printed book, as I always wanted, with deeper explanation how stuff works.

I don’t want to look like I’m hiding something there. I know my coding habits are sometimes obsolete, but I’m strictly against today’s beloved bloats, like giant classes in PHP even in situations, when simple function would do the job as well. I want my code quick and sleek, performance tests speaks loudly against OOP in PHP. In latest PHP builds it’s better, but still little slower and more memory consuming.

On the other hand because I decided to unify the code, I have no choice but use objects. Making full OOP in PHP is like mounting wings on a car and trying to fly with that – it takes a lot of time and effort and the result is questionable. So I will try use the OOP wisely, only in situations, that otherwise would be problematic (like no object for “toolbox” or app itself).

Except for that, I don’t want anyone to change anything in the code (PHP, JavaScript), everything is there for a reason. If you need anything to work in a different way, you may consider to look somewhere else. The framework is built to be “just enough” for the purpose it serves. I want full out-of-the-box experience.

During implementation it’s possible to add a new module, but again – with deep respect to the ecosystem. The only part I’m completely OK about changes is CSS, but even there I created everything you may need.

Regardless, I’d love to hear a suggestions or constructive criticism (preferably with refactored code), if it stays in defined boundaries.

Friday, May 17, 2013

Pythagorean theorem in Q Editor

Last month I wrote about Q language for scripting events in QetriX. I mentioned I created an online editor, but I didn’t show it here. So here is a screenshot: (it’s shrinked closer together as I wanted to save some pixels)

On the very left there is a block schema, where you can see a flow of all commands, because Q utilizes a lot of “goto” commands and it may be easy to get lost in the code.

In the gray box, titled “Events”, you can see the source code on the left and a debug output and trace on the right. Output is like a console, but here is nothing to print out. In Trace you can see what commands in what order (and with what result) has been executed.

“RESULT” is the value, what is returned back into the code after processing the Q script.

In the script I defined two constants, but you can get those input values from QetriX, or e.g. GET, POST or COOKIE variables. So first two lines contains numbers 3 and 4. Pythagorean theorem for calculation the hypotenuse (variable “c”) is: “c = sqrt(a² + b²)“, so first of all we have to calculate square power for “a” and “b” (lines 3 and 4, showing two different ways how to achieve that, using “mul” and “pow” commands). Then we add those two results together and finally we calculate a square root of the sum.

There are no gotos or decisions, so the code is nicely straight – from Start (“S” circle) to End (“E” circle). Final result of the code is the same, as the result of the last line.

Tuesday, May 14, 2013

GeoQetriX

I’ve always been into geographic stuff and I’m not talking about geography back at school :) The very first version of what one day emerged as QetriX already gathered coordinates and I tried to visualize them on maps, especially custom made (calculated) from vectors.

I bought an outdoor GPS device from Garmin (even it costed me an arm and a leg) and visualized tracks from our long distance walks (sometimes more than 30 miles in a single day).


Old Q3X app with map module, utilizing Google Static Map API

One day I made a screenshot of ortophoto area from Mapy.cz, a great Czech competition for Google Maps, geolocalized it and made math function to put POI (points of interest) icons on it precisely. Then I found a function to calculate a distance between two points, because on spherical object it’s not just a calculation of hypotenuse, and used points for such calculations.


Map of POIs in QetriX two years ago (2011)

Years later, after I designed the Particle, I started to think about “geographical particle”. I have to admit I still didn’t make any further progress, I’m stuck with three tables: point, line and area. Pavel (he’s a surveyor) told me about “topology”, which consists right of these three components. There are points, line is a connection of two points and has an area on each side.

It’s easy to convert it into 3D afterwards just by adding 3rd coordinate to the point, because no matter how hard you try, you always end up with point-line-area. And I’d like to get rid at least of one table, but I can’t see how. Pavel encouraged me to do so, referring to what I did about Particle. We’ll see how successful will it be this time.

Wednesday, May 8, 2013

Android App

Java has always been somehow unlucky for me, even though I have a lot of experience with similar languages, like C# and JavaScript. I tried it and failed several times over last five, six years. I was able to make the Hello World to work, but nothing beyond. This applies for Android as well, I remember installing the SDK two or three times in the past. Maybe because I used NetBeans and then Eclipse. But this time I tried IntelliJ IDEA (community edition) from JetBrains.

The first steps were obvious: File > New Project... > Android Application Module, fill the project form and create the project, package “com.qetrix”. My test device is old Android 2.2, so I selected this one and API 8. But what now? I knew something about Activities but I had no idea what it’s all about. I read somewhere it’s like a Controller in MVC. OK, but what about view (something like Form in .NET)?

I tried to add new GUI Form, but it was dead end. I tried tutorial from JetBrains and I learned the GUI is defined as XML file in res/layout/ directory. I created new XML and – voila! Nice. I started adding controls and for me it was quite understandable.

I created the screen with a list of databases (ListView with ArrayAdapter) and compiled it. After a while it launched an emulator and after it booted and I unlocked the screen, the app appeared. Fantastic! :)

Then I created new form as Login, set it as startup and launched the other from this one, using “.startActivity(myIntent);“. This was a pivotal moment for me, from this point on it was just a matter of time, manuals and best practices.


Login screen (Czech locale). Oldschool – I know :)

The development for Android is really fun after all :)