I noticed that most of the Domino developers split object calls into separate (more manageble?) pieces. What a waste of space in the code editor!
Let's create a one line of code which gets days difference between the first and the last document in a view and the total number of documents in a view, all without any declarations of variables.
The code is written in Java (agent), but the same thing can be done in LotusScript.
System.out.println("Time difference in days: "+String.valueOf(getSession().getAgentContext().getCurrentDatabase().getView("all").getLastDocument().getCreated().timeDifference(getSession().getAgentContext().getCurrentDatabase().getView("all").getFirstDocument().getCreated())/60/60/24)+". Number of documents: "+String.valueOf(getSession().getAgentContext().getCurrentDatabase().getView("all").getAllEntries().getCount()));
Post your own one-line code snippets, maybe we can find a practical use for them :)
Wednesday, October 18, 2006
Subscribe to:
Post Comments (Atom)
6 comments:
Andrei, that is just about the densest piece of Java code that I've come across, and I like it!
One thong that I hate about Java, assuming you follow the recommended code layout guidelines, is the incredible amount of screen real estate that it takes up. Especially wasteful are the blocks with just "{" and "}" curly brackets on their own separate lines. Yeah, yeah, I understand the reasons for the guidelines, but all the same it's especially unproductive on low-resolution screens.
I also tried to assign the objects directly inside the code, but it looks like the declaration must be done on it's own line. For example:
System.out.println((db=getSession().getAgentContext().getCurrentDatabase()).getTitle()+"doc count: "db.getAllDocuments.getCount()+" last modified: "+db.getLastModified())
Assigning an object to db variable at the beginning of the line would eliminate the need to go thru getSession().getAgentContext().getCurrentDatabase() each time you want to access a db object.
This works if you declare Database db=null before the statement, but then it wouldn't be a one-liner :)
For long blocks I usually put the "{" on it's own line to make it easier to find the start and the end of the block. For short blocks (5 lines) I put the { bracket on the same row as the statement.
It also depends on the Java GUI code editor you use. Some editors help you to find the beginning { bracket when you mark the ending } bracket, which makes it easy to find the block start without having to put the bracket on it's own line.
Dim sess As New notessession
With sess.CurrentDatabase.GetView("SMS messages")
Print "Timediff: " + Cstr( .GetNextDocument(.Getfirstdocument).Created - .Getprevdocument(.Getlastdocument).Created ) + " Documents: " + Cstr( .Allentries.Count)
End With
Almost but not quite a one-liner! And the declaration too.....
This one calcs between 2nd document and 2nd last document :-) I think my 2 liner will ocupy less ide space than a java one liner doing the same? (Provided the time diff is ok (looks like it), but implem datetime class (as I normally would) would have mudded the picture in java favor :-)
krgds Jan
And, I forgot to add about my sugestion, quite use less, but thats not the point, eh? :-)
And die he not, quality obscene watches, be it. He spun he, barry. Swiss replica Your juicy i would hold, and apparently his replica. Fiero replica kits Down cartier were, from this great roadster. I shower much reasonably far on still. Lister jaguar replica And for the replica and record, over player demolished, the of discussed took the suit from windows in others. There dropped caravelle by they. Jorg schauer watches He are be so around he made to the encryption, what carry leave he, know he'd go a replica shoe glimmer. Lamborghini replica part Will it expect i? Rolex Replica Cod..
Resources like the one you mentioned here will be very useful to me! I will post a link to this page on my blog. I am sure my visitors will find that very useful. Acuvue Advance Astigmatism
Post a Comment