Sunday, September 16, 2012

EA Server

I've been posting about Powerbuilder a lot lately. The PB application, I work with currently is actually an n-tier application written in PB, Java and JSP. The application is built around a middle tier from Sybase called Enterprise Application (EA) Server. It's also called Jaguar (which is actually a part of the EA Server). A quick search for EA Server in google brings up Electronics Arts page, a gaming site. Search on Jaguar brings up all kinds of other things. So, there is not a lot of help on EA Server, though Sybase's own site has a wealth of information on the product. In my current project, we rely on EA Server for all our business rules and multi-tier application support. I am learning about the product in an effort to improve our architecture and thus our application performance. I will my share my experiences here, so it can benefit others trying to learn or use the product.

EA Server is an Application Server like Oracle Weblogic, IBM Websphere, JBoss etc. It is a Java container like all others mentioned. EA Server is a full blown Java server, so it supports Servlet, JSP, EJB and JMS. Apart from that, it has a speciality of being able to run PB objects as well. With support for CORBA (IIOP) and COM (on windows machines) components, it enables PB developers to develop application modules in PB, Java, C++ that can talk to each other through CORBA. For e.g., we have a site built using JSP pages that "talk" to PB objects. Recently, I developed a wrapper in Java for PB classes, so our Coldfusion applications can use PB objects as well. With this setup, we are able to implement an n-tier application in various languages.

While researching the issues and figuring out new methods to improve our Server performance, I realized how powerful the server is. I currently work with EAS 5.5. The latest version is 6.4. In 6.x, Sybase rearchitected the product completely to be more Java centric. To be able to do that, they included a Jetty Java container and wrapped each PB object as a J2EE object, so everything runs as Java objects. I haven't tried this version yet, but it sounds interesting. Unfortunately, from what I heard, Sybase (SAP) is thinking of getting rid of this completely in a few years and re-architect PB support into SAP's Netweaver server. So, really the knowledge about EA Server may disappear in a few years. (This is exactly what happened to Forte! Is it my luck or what?).

Irrespective of the fate of the EA Server, I believe the techniques learned in this exercise will be useful with other servers as well. I am already, trying our web app in Apache Tomcat which can then connect to our PB objects running in EA Server. I will share these experiences here as well.  So, if you are interested in EA Server or writing n-tier in PB or even how to make PB talk to Java components usingCORBA, please check back in.

Quick Tip - Oracle SQL*Plus: HTML output

Recently, I posted about SQL*Plus, a database querying tool from Oracle. Like I mentioned there, the tool is rudimentary and has some basic file handling capabilities. It has a command, SPOOL, to write the console output to a file. Traditionally, you only spooled the output to a text file. Some releases ago (I believe in 8i), Oracle included option to spool the output in HTML format. Useful when you are dumping data from tables (Have you tried dumping table data in plain text file format??) and for generating simple reports.

To generate HTML output from SQL*Plus, all you have to do is add markup option either on command line or inside the script. By the nature of it, it is only useful when you are spooling the output. Just add below to the script before spooling: and the output will be spooled to the file mentioned  in HTML format.
SET MARKUP HTM ON SPOOL ON PREFORMAT OFF ENTMAP ON -
HEAD "<TITLE>My TABLE Listing
</TITLE> -
<STYLE type='text/css'> -<!-- BODY {background: #FFFFFF} --> -
</STYLE>" -
BODY "TEXT='#000FF'" -
TABLE "WIDTH='90%' BORDER='5'"


...
spool dump_table.html


...

SPOOL off

That's it. Just be aware that the output file will be larger than the usual text file spool. By the way, the hyphen "-" at the end of each line is the line continuation character in SQL*Plus. So, it's really one line command with several options.

Alternatively, you can specify the HTML option on the commandline as shown below:
sqlplus -S -M "HTML ON" <user>/<password>@<SID> @dump_table.sql > dump_table.html

The option -M "HTML ON" is equivalent to MARKUP HTML ON in the script above. The option, -S is for silent, which turns off spurious output from SQL*Plus.

 

See here for more about creating HTML reports using SQL*Plus.

Monday, September 3, 2012

My Journey with Ubuntu Contd - Switching Desktop

Last time, I posted about upgrading to Ubuntu 12.04, Precise Pangolin. It has a user interface (desktop) called Unity. It looked different from Gnome desktop I got used to in ver 10.x. It was an adjustment, but it was easy to get used to. One problem I had though was that it kept freezing up at random. I believe this is a bug in the interface, judging by the bug reports opened for the issue.

Installing a new Desktop


While researching the issue, I found out that I could replace my desktop interface easily with Gnome desktop I used to like!! This blew my mind!! What? Replacing desktop? You mean re-installing complete OS, right? At least, that's what I am used in the MS-Windows environment. No, not with Linux. Here is a link I used in getting the new desktop installed. This put Gnome right beside Unity. All I had to was switch to Gnome when I logged in (See Fig. 1). So far, it's working fine. Apart from this, my applications and settings are still there. It connected to network and printer right away, so I didn't miss anything. (Note: While logging in I had to use Gnome (No effects), to get the same desktop look I had in 10.x.).

[caption id="attachment_455" align="alignnone" width="274"]Gnome in Pangolin Fig 1. Gnome in Pangolin[/caption]

(Note: to get to this list, click on the ubuntu icon while on the login screen. This is like pressing F8 to get to Safe/Normal mode in MS Windows).

Coming from MS Windows environment, I didn't think this was possible*. Not that I am a Micorsoft basher or anything. I've worked on MS Windows, most of my working career. I believe, MS-Windows is part of the evolution process a lot of us went through in the Software industry. Even so, I couldn't avoid being disappointed with MS-Windows. First of all, there is no such option with MS-Windows. With windows, if you wanted a different desktop, you would have to reinstall different version of OS. Remember Vista? When it came out it was buggy. Microsoft  offered that you could "downgrade" to XP one time. But then, you lost the shiny new OS called Vista. On top of that, when I switch to a new OS like that, I am sure to face an issue or 2 to get it to work with the set-up I have. No, this was not supposed to be possible.

(Note *: There were some custom desktops available from 3rd party, but nothing fitted in smoothly, as Gnome did here! Further, they typically ran on top of the existing windows desktop, so they were slower).

Secret lies in Linux Architecture


So, I researched this a bit more. Apparently, Ubuntu (actually any linux and Unix)  OS is built in a modular way. One layer can be easily replaced without disturbing another. As you know, underneath it all, there is kernel, the core shell in the OS. Then there is command line interface which is what we were used to, if you were using Unix. Add to that, a windowing layer, you got a Desktop. So far, this is the same way in Windows. (At least it used to be through Windows 98). But there ends the similarity. Fig 1, shows the building blocks of a Linux OS.

[caption id="" align="alignnone" width="499"]Linux Archirecture Linux Architecture - Courtesy Paul Cooper (pgc) on Flikr[/caption]

So, when I installed Gnome, I basically added to the desktop layer at the very top. The underlying layers (including Window Manager and X-Windows) were unaffected. This is why, my set-up was unaffected. Wow, truly modular programming! Similarly, I could actually replace a hardware and Linux would simply find appropriate drivers (or you can install it) and everything is working again! I couldn't help compare this to MS-Windows, if I changed hardware (even as simple as moving the hard drive with the OS to a new machine), it will be a nightmare to get it working again. Kudos to Linux community.

I really hope they fix the bug(s) in Unity, so I can get back to it in the future. But, I am not exactly missing anything here. Because, Gnome is actively developed in the community. Further, my desktop is definitely running faster than with Unity. (Another complaint about Unity on the web).

P.S: If you are wondering how I got the screen capture of the logon page, that's another strength of Linux (Again, you couldn't do this in windows). There is a whole slew of things to read up on X-windows. I will post more on this later. For now, refer to the link in the references below.

References



  1. Gnome Desktop

  2. Unity Desktop

  3. Ubuntu

  4. How to add Gnome Desktop to Ubuntu 12.04

  5. Another site about installing Gnome Desktop

  6. How to get screen capture of the Login page


Now I can proudly say, my PC is

Learning Opportunities online

In Computer Science, we constantly face the challenge of "keeping up" with technology. If you catch up with one, chances your skills are outdated within a few months or years. Part of the problem has been lack of affordable learning opportunities, just to keep up with trends in the field. Of course, there are courses available in Community colleges and local universities, for continuing education. They were challenging in terms of logistics and time. What if you can learn at your own pace and they are affordable and of good quality? Wait no longer!

Did I say affordable? Read Free! Recently I found that a lot of universities are offering free courses online. These are real courses that are offered in classes in those universities, with home works, programming assignments and even exams. The courses are literally free, including study materials online. Some courses even offer some kind of Certificate. They do not offer any course credits though. The universities include reputed institutions like Harvard, MIT, Princeton, Stanford, UC Berkeley. You can read more about this in this NYTimes article.

For more information on the courses offered, check out the links below.

This blogger has listed a few. MIT has a Open Courseware that offers lectures from their courses online.

I am currently taking a course at Coursera and it has about 60,000 students enrolled from all over the world! It's definitely opening up new avenues in bringing technology to those remote areas of the world.Personally, if not anything else, I am using it to keep in touch with the trends in Computer Science. This is also a great opportunity to get your hands on newer technology, if you are stuck with old technologies at work!There is one course coming up at edx,org, offered by UC Berkely, called SAAS - Software as a Service. In this course, one can pick up some cloud programming and hands on experience in Ruby on Rails.

If you are a self learner, there are a lot options throughout the web. Youtube has been a great resource for several topics. Some great minds have put together videos explaining complex topics like Algorithms to mathematics modelling. There is also wikibooks and even a wiki university that have great resources for a self learner. But if you need structure and discipline of a classroom to learn, above sites will help.

So, if you want to brush up on those data structures before the next interview, pick up one of those links and have fun learning!

Sunday, September 2, 2012

To OO or not to OO

I originally wanted to name this post "Object Oriented Concepts - Contd....", but then the Hamletian dilemma came to mind. Every programmer faces this, even today, many years after OO has been widely accepted. Part of the problem is that the OO paradigm requires a change in how we think about a problem.

As we saw earlier, in traditional languages we always think "how to do a task" in a procedural sense. This we could adapt to - after all, we humans are good in giving instructions and making recipes and grocery lists. Programming was a natural extension of this - we told the computer what to do and how to do it. We told the computer what to do while feeding data (nouns) required as parameters to these commands (verbs).

When it comes to OO, we have to start thinking what will be the objects we need and "leave" it to those objects to do the work. Really, it's just repackaging, but it's not easy. We are now forced to think of everything in terms of objects. If it's objects like animals, cars, people etc that are typically used in examples about OO, we can understand. But the moment we try to come up with objects for abstract concepts and purely action oriented tasks, it becomes a daunting task.

Baking a Cake

For e.g., let's look at a simple problem of baking a cake (no disrespect to the chef in the kitchen, but let's abstract it here as simple task here for a minute). A recipe typically talks about how to get, do, heat, bake etc. All verbs. Interspersed will be details about data to be used - how much flour, how much sugar, what temperature, how many minutes etc. These "nouns" are used as parameters to the recipe and off we go. Of course, every now and then people try to "reuse" recipes by switching ingredients.

This simple recipe for a cookie , that highlights these points. It has an instruction with 3 simple steps to make delicious cookies. It has some ingredients (attributes) mentioned - dough, apricot jam, and parameters like temperature at 350 degrees, time for 15 - 18 minutes and 1/3  cup of jam. It is straight forward and it even "reuses" recipe for "basic sugar cookie dough"! We certainly know who is making this cake - you, and the ingredients and implements you will be using.



In our abstraction in a procedural language, we created a program with the instructions to bake a cake. We probably broke down each step into a separate procedure (or function), and created a main function that looked like the recipe and called these functions to get the baking done. We created some variables outside of these functions for the parameters required. This works and even is simple to write. But, we assume a lot of things here, like the main function itself acts like the baker executing the instructions. Controlling the oven may be built in as a built in function, but at some point it has to call something to make it happen.

In OO, the task gets a bit more complicated! First, you would have to start thinking differently. Now, you will have to think about the nouns first. Of course there is cake, the final product. But, there is also the bowl, oven and a fictitious baker - may be you, but object none the less. These other objects were included in our procedural programs, but were not given much importance. Any reusable, replaceable parts of the program will now have to be separate objects. In our example, if we make the Oven and the Baker and bowl objects correctly, they could be reused in making/baking pies as well as switch to make or even pot roast! Guess what, you can even replace the baker easily!! This is what makes OO so reusable and to some "so bloated!".

If you are interested in OO cakes, here is a link on a cake OO.

 

 

 

So, To OO or not to OO?


OO is almost everywhere around us. Language after procedural language (recently PHP, Coldfusion, ABAP, Flash ActionScript) have added OO capabilities in recent years. But then, there are also others that write about the difficulties and shortcomings of OO. The post titled  Debate Still Rages Over Object-Oriented Programming discusses such dilemma. While you are there, don't forget to check out  Marc Funaro's orginal post here: How OO Almost Destroyed My Business. He has articulated very nicely, why he couldn't and didn't have to switch over to OO completely. And see here for a funny take on Java's OO techniques! Irrespective of such views, OO is here to stay. Even if you don't use OO technology currently, chances are, sooner or later you may be exposed to it.

OO methodologies could get complex and could actually distract a developer from the original goal of getting a working program quickly. General rule of thumb I have, is to use procedural for any small (read quick and dirty - most of my utility programs and scripts fall under this) programs and use OO methodology for any larger (business, corporate, enterprise, framework) programs and programs that have potential to grow in the future. (The truth is, even the quick and dirty program/script could outgrow their originally intended lifetime and objects do creep into those every now and then!). OO definitely enforces certain planning ahead of time, so it takes a bit longer to develop it upfront, but if a program lives long enough, re-usability makes up for the cost over time.

In the cake example above, if I am just making a cake for the family on a weekend, simple procedural implementation would be fine! But, if you are going to be making a cake each weekend or thinking of starting a bakery with several branches down the road, then I better start thinking in OO terms, so we don't have to re-invent a lot of stuff later.

General Design Considerations
Irrespective of whether we use OOP (OO programming language) or not, we are bound to use the modern techniques like Abstraction, Encapsulation, Inheritance and Polymorphism in our program designs. Underlying all these, is the code reuse, data hiding and of course modular design. These of course are not OO by themselves, but are the foundations of OO techniques. By nature of it, OO is almost automatically modular.




  • Keep your code Clean




If the code is not "cleanly" written,  even you cannot understand it a year later. By clean, I mean well commented (documented) and following some coding standards and best practices.


As for coding standards, what's good for one language isn't always good for another - for e.g, in Java we follow Camel case for naming variables while in PB  identifiers are mostly in lower case. So, if your system includes programs in different languages, make sure to include language specific standards as well. Also, best practices for any language may change over version. For e.g., there may be newer constructs and/or functions may be available in a later version that are more efficient than what was available earlier. Make sure to keep up with those in your programs.


OO Note: OOP languages such as Java promote commenting and documenting of the programs easier, with the Javadoc tool (even more so, with IDEs like Eclipse and Netbeans). A well written framework for Java, actually enforces some coding practices automatically. But we can achieve such coding practice with libraries of well written API. A well commented header file distributed along, could act as the documentation for the API.



  • Keep it modular



By breaking down your program into smaller modules, your program becomes more manageable. If your program includes specific modules for various functionalities, it will be easier to replace or rewrite or even add a specific module without affecting the entire program. For e.g., if you isolate all database related functions to a separate module, then if your database changes, then all you have to do is to replace this one module. In our cake example above, we could simply add an object for Microwave and start using it instead of Oven, if oven breaks down!


OO Note: Writing such "modular" programs comes naturally in OO languages as the program is essentially built around objects (or classes). But this concept itself is not new. For e.g., in C, you can achieve this by keeping different modules in separate source files), your program becomes more manageable.




  • Make the code Reusable



How many times, have you "cut and pasted" your code from one source file to another to "reuse"? If the program is properly designed, then the reuse would be much easier and automatic.


OO Note: In OO, inheritance promotes reuse naturally. A well written framework or class libraries contain reusable classes and methods. Apart from using the classes in the framework themselves, one could extend those via inheritance and thus more custom classes for others in a company to reuse. For e.g., you can create custom loggers specific for your need, by extending classes in log4J library.


But again, this is not specific to OO. In a procedural language like C, one could build libraries of reusable functions. While C doesn't allow extension through inheritance, reuse can be achieved through composition. An inheritance is typically defined by a is-A relationship, while a composition by a has-A. Here is an excellent article that compares the two.