Drools Rules!
For anyone contemplating using a Rules Engine here is some free advice. In my career I have had the chance to use three different Rule Engines (ILOG, QuickRules and JBoss Rules), of all the three I have found JBoss Rules the best, I love it!
JBoss Rules used to be a standalone project called as Drools before it got merged into JBoss, the beauty of Drools was it was simple, no fancy tools or interfaces, just a plain old jar file that you included in your classpath and started using. And best of all it was and still is free, so less of a battle with management.
JBoss Rules works with POJOs and integrates well with Spring and best of all you could learn it quickly. Performance wise, I don’t remember the exact numbers but we did have over 100,000 different rules and it would go through them in seconds. There was never a problem on that end.
It has been over a year that I have used it and when I was using it, it did not have any fancy interface, so we built a rudimentary interface for loading new set of rules into a running application and it worked out very well.
All the rules are stored in a place called ‘Production Memory’ I just call it a blueprint, every time you just make an instance of this blueprint, assert the facts into it, get results and throw away the instance. Creating an instance was very fast and lightweight, and while there are instances floating around in your app you can update the blueprint and the next time an instance is created the updated rules would be used.
JBoss Rules gives you many options for writing rules, you can either write em using spreadsheets (also called Decision Tables) or write them using the provided DSL. Spreadsheets are really good if you have small number of columns, I’d say as long as they fit your screen you are good, once you have to start scrolling vertical, debugging gets a little difficult.
NOTE: do not let your business people edit the spreadsheets, if you have to, give em a website where they can upload and verify it. Regardless of what JBoss says, these excel sheets follow a strict convention, one minor formatting error and you will be in trouble. I wrote a simple program that loaded these spreadsheets and verified if it worked before doing anything else.
Testing is a must, sorry but you cannot get away from this. Based on your data (or facts) many different rules can get active and then unless you specify you own Conflict resolution strategy it will use the default strategy and you may get some unexpected results. This was probably the most tedious part of using a Rules Engine. Also things like ‘OR’ and ‘AND’ work different that what you are used to. The more rules you have to more testing you will need to do. If there was a wish list for JBoss rules features somewhere I would say a rules coverage feature would be nice to have.
I have been told ‘Jess in Action’ is a very good book to read if you wanted a good introduction to Rules Engines and it tells you how to use Rules, like something I have heard is you should use Rules Engines to get the result and then apply the result to your data and not let the Engine itself modify the data.
Anyways that was my brain dump on Rules Engines.
Loving Clojure
I seem to be liking Clojure …
Let me backup a bit, in the last couple of weeks I have been debating between picking up Scala or Clojure (don’t get me wrong Ruby is still my favorite).
I always wanted to pick up a functional programming language so I dabbled a bit with Erlang and Haskell, liked Haskell a lot but without much practice it kind of died (sad times) and Scala seems too much like Java, yeah I know it seems to have a bigger crowd than Clojure and there are a lot of big names behind it.
Maybe that’s exactly why I choose Clojure (since its the underdog), or cause it is different enough from Java or simply cause it has a better syntax and seems more elegant (apparently Clojure has better integration with Java, don’t quote me on it), anyways I decided to learn Clojure.
Peepcode has a nice screen-cast to get you started off on Clojure. If you are on the Mac there is a nice bundle for TextMate and anywhere else Netbeans with the enclojure plugin seems to be the best.
On a side note it seems more and more that Netbeans has the latest and greatest plugins for everything, then comes IntelliJ and finally eclipse, what’s going on with eclipse ? has it reached its peak and now it will start dropping off ? but on the flip side there seems to be more and more apps built on top of the Eclipse RCP like Xmind, so is Eclipse no longer going to be the leader of the IDE and just become a platform for building RCPs. This of course depends on what Oracle is going to do with NetBeans, I really hope they give the same amount of love to NetBeans as Sun did.
Ok getting back to Clojure, don’t get your panties in a bunch when you see all those parenthesis, it is just the layout that is shocking, indent it well and it is no more than what you are used to.
Here’s an example
(defn fac
“Returns the factorial of n, which must be a positive integer.”
[n]
(if (= n 1)
1
(* n (fac (- n 1)))
)
Is same as
(defn fac [n] (if (= n 1) 1 (* n (fac (- n 1)))))
But the first one is a lot more easier on the eyes (even brain?) than the second one. Most examples that you see look like the second one and it frightens people, don’t let that stop you take my word and go for it.
Clojure seems to be very easy to pick up, things seem very intuitive, like the other day I was wondering, how to return a default value from a map if the key is not found and there is was right there in the api.
(map key default-value)
So simple! I was easily able to extend the examples that came with the peepcode screencast. Anyways I have started on this path, let’s see where it goes.
Language wars are the new IDE wars
(I feel really sorry for Managers, every programmer has his/her favorite programming language and is trying to sneak it into the system. And you know what, it is already in your code base, sorry but that’s the truth and whatever side you take, you will end up loosing. )
I think people used to have IDE wars cause they only had one primary language to work with, but now with the explosion of languages and almost all of them having some port that runs on the JVM everyone is either trying to sneak it in or advertise the virtues of using it. And that ultimately results in a passionate email war.
And of course if you have, somehow magically gotten past that there is always the discussion on the best IDE for that language, hehehe let the wars continue.
Integrating Facebook Connect into your Web App
Lately I have been spending time researching on how to integrate with facebook connect. There is a ton of documentation on the facebook wiki page, but as with any wiki you need to know what you are looking for. I am going to document here what I found.
For the really impatient (like me) check out this video.
- To begin with go to this Wiki page on facebook to get familiar with facebook connect and reasons for using it.
- Install the facebook developer app into your facebook page (makes it easy to keep track of your api keys and your webpages ).
- Next on the facebook developer app register your domain and it will generate the api key and secret (don’t worry about saving it you can always look it up from the developer app).
- Once you have done that you will need to download and place this file xd_receiver.htm into your applications root folder. (For step by step instructions to do this go here.)
- Include this tag in every page that you plan to use facebook connect on.
< script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php/en_US" type="text/javascript" >< / script > - And also include this snippet to initiate the connection.
< script type="text/javascript" > FB.init("a8072b7845a8815f63966e90abe4a1e0", "/xd_receiver.htm"); < / script >Should be in the body not head - Place the login button
fb:login-button length='long' onlogin="successful_login();" - You need to create the function successful_login, that will do something when facebook authenticates the user. I just went and pulled the user’s picture and show it. The code for that is here
$("#login").html("< fb:profile-pic uid='loggedinuser' facebook-logo='true' > < /fb:profile-pic >. Welcome, < fb:name uid='loggedinuser' useyou='false' >< / fb:name >.");
And that’s about it, if you want you can check out my example at devender.net
TextMate Love
I love TextMate, working in it feels no natural. Although I have been an avid VI user, more and more nowadays I keep opening up TM. And it would be so nice if TM were available on Ubuntu.
And yeah trying to make gedit act like textmate sucks donkey b****
UPDATE: Ok so I tried netbeans and also ruby mine and I still think TextMate is the best.
Upgrading To Snow Leopard, What a pain!!
Man what a pain, the actual upgrade was very smooth but then my mac ports broke followed by sqlite, mercurial ……
- First thing you will run into is MacPorts are broken. To fix it is download it again and reinstall (apparently each version of MacPorts is very specific to the OS) and after you do that, un-install and res-install all your ports, this will get apps that will work with Snow Leopard (the 64 bit version). Here’s what I do not understand when Ubuntu can maintain apt-get why can’t Apple maintain mac ports and make it easy for developers ?
- Anyway moving on, if you had Mercurial installed from MacPorts, you can forget about it (Since mercurial is dependent on python26 which is at present broken with MacPorts. Workaround is, just download the mac version of mercurial for mercurial’s website and install.
- Reinstall sqlite3.
- If you had installed Ruby and Gems manually then you will have to re-do it again here are the links to do that reinstall ruby, reinstall gems this will setup the 64 bit version of ruby.
Great, now back to some productive work @#$@!$%@
Keywords uninitialized constant SQLite3::Driver::Native::Driver::API, python26,
Pragmatic Thinking & Learning
- Have you ever felt that you have reached a plateau in your career ?
- Read the pragmatic programmer and couldn’t get enough of it ? or wanted a follow up to it ?
- Felt stuck ? Reached a stalemate ?
- Had great many plans but never really completed them ?
- Knew there is something better but did not know how to reach it ?
- Wanted to get better, just did not know how to ?
Well I can with 100 % confidence tell you the answer to all these questions and more is reading the book ‘Pragmatic Thinking & Learning : Refactor your Wetware‘ -by Andy Hunt .
In this book Andy shows us
- Why the brain works as it does?
- How to move beyond beginner level performance to expertise ?
- What are our cognitive biases or bugs in our brain and how to overcome them?
- How to learn deliberately ? (learning that sticks).
- How to harvest your ideas and insight ?
- How to stay sharp and why is it important ?
- and so much more.
As I was reading the book I could already see changes in me and my performance (not that kind). I can honestly tell you this book has helped me.
Some helpful Sqls for Oracle
1. For finding out the current running sql for a particular user
SELECT a.sql_text FROM v$session s, v$sqlarea a WHERE s.user = 'USER' AND s.status ='ACTIVE' AND s.sql_hash_value=a.hash_value AND s.sql_address =a.address;
2. To find locked objects in Oracle
3. To see all the seesion for a user
select * from v$session s where s.username = 'PROQ';
4. To see locked objects and the session
select oracle_username || ' (' || s.osuser || ')' username
, s.sid || ',' || s.serial# sess_id
, owner || '.' || object_name object
, object_type
, decode( l.block
, 0, 'Not Blocking'
, 1, 'Blocking'
, 2, 'Global') status
, decode(v.locked_mode
, 0, 'None'
, 1, 'Null'
, 2, 'Row-S (SS)'
, 3, 'Row-X (SX)'
, 4, 'Share'
, 5, 'S/Row-X (SSX)'
, 6, 'Exclusive', TO_CHAR(lmode)) mode_held
from v$locked_object v
, dba_objects d
, v$lock l
, v$session s
where v.object_id = d.object_id
and v.object_id = l.id1
and v.session_id = s.sid
order by oracle_username
, session_id
And then kill the session with this
alter system kill session '94,2168';
5. Tables by user
select owner,count(*) from all_all_tables group by owner;
Should a correct solution be elegant too?
Many times when engineers propose a design/solution we are told ‘Well lets just get over the hump for now and refactor it later” or ‘oh, that’s an elegant solution but lets just get it done for now’ and the worst of all you are just ignored. (Makes you think if you are speaking in a different language)
This almost always pains me, I just cannot understand how can a solution be correct and not be elegant to me a complete design is something that is correct, elegant, maintainable and easy to extend. Something that will stand the test of time. Something that can be reused.
I learnt the hard way every thing that you ever write and put into the system, someday you will have to enhance it, so would it not be better for you if you do it right the fist time around ?
I guess it is the engineer in me, I get bored if there is no puzzle to solve.