In response to: So Programming Language Really Does Matter @Henning, in my opinion, IBM is absolutely running an experiment,
but a rather clever one. The JSF specification is over 8 years old,
and SSJS has been around even longer (Rhino, for example, was
orginally created in 1997, and LiveWire was released in 1996), so
the underlying technology isn't exactly new. On the other hand, in
many ways, XPages have allowed Domino to leapfrog most of the web
development platforms that are currently trendy... a phenomenon I
honestly never thought I'd see.
I found this video about SSJS on the YUI Theater site intriguing:
http://developer.yahoo.com/yui/theater/video.php?v=isaac-ssjs
It's a short clip (at least compared to most on that site), but the
implications are clear: platforms implementing SSJS are still
considered leading edge, but there's strong momentum behind this,
and over time, having a rock solid implementation is definitely
going to be a strong selling point for any platform.
In case you're curious, Wikipedia has a listing of all known
implementations of SSJS:
http://en.wikipedia.org/wiki/SSJS
...and yes, there's a glaring omission. :(
|
Re: So Programming Language Really Does Matter
|
A deeply ingrained habit of mine is using ampersand to concatenate strings in LotusScript (when I'm not bypassing operators entirely, such as using NotesStream or StringBuffer to optimize massive concatenations) - so deeply ingrained that when NTF asked me today why I don't use plus instead, for a moment I couldn't remember my original reason for switching... but after mulling it over briefly I remembered that I hate type coercion with a passion. It bugs me because it tries to be too smart and often fails. Just like extended syntax. For example:
"100" + "200" = "100200" This may seem obvious: we're concatenating 2 strings, so it takes the value of one and appends the other. But... 100 + "200" = 300 The LotusScript interpreter decides that, since it's starting with a numeric value, you're obviously trying to add another numeric value. Since in this case the string can be converted to a number, it does so and adds the operands instead of concatenating them as strings. So, logically: "100" + "200" = ...300? That's right: plus is primarily an addition operator, so if there's any possible way it can remain one, it will. In fact: 100 + "two hundred" = type mismatch - at compile time if it knows the latter is a string, at runtime if it's a variant... reason #372 why variants should be used sparingly and with caution. Speaking of which, I think it was Nathan who once told me, "Variant should have been called Deviant... 'cause it'll accept any object". Yeah, I know, ew. But you gotta admit, that's darned funny.
So how did he convince me plus is better than ampersand despite my pedantic aversion to coercion?
- (Author's note: this was actually a third realization, which came after the discussion.) In LotusScript string concatenation, some coercion is unavoidable. Since ampersand's only valid use is as a concatenation operator, any scalar entering the operation is treated as a string whether you wanted it to be or not. So unless everything's a string to begin with, it's coercing anyway, it's just safer. But if we're subscribing to a "flexible input, strict output" philosophy, we're already making sure we know what data type we're dealing with and handling it appropriately, so ampersand doesn't really gain us much... it's only when we're being lazy about this that ampersand saves us from returning unexpected results.
- Whenever possible, it's helpful to use conventions that are optional in one language but required in another. In Formula, but - more importantly, over the long haul - also in JavaScript and Java, we don't have a choice: we have to concatenate with plus; might as well do it in LotusScript too so that we're spending more time thinking about how to implement the actual functionality at hand and less time trying to remember what operators to use in the current language... same reason I always surround my conditional expressions in parentheses: I know LotusScript doesn't force me to, but JavaScript and Java do, so why erode a good habit just because LotusScript would allow me to be lazier than that?
- In XML, an ampersand must be entity-encoded; a plus can be left alone. This was the "you had me at hello" argument. For the foreseeable future, any convention that allows my code to be handled more easily within an XML context is likely to appeal to me, even if it forces me to abandon a long-held alternate approach.
Anything you can think of that I'm overlooking? If not, I'm switching to plus effective immediately. That is, as soon as I get back to writing LotusScript... it's been nothin' but Java for me all week.
|
I was wrong: plus is better than ampersand
|
How many times (this week) have you needed an object representing a past or future date in LotusScript? Pretty standard stuff... you instantiate a NotesDateTime with Now, then call an adjustment method to correct the date: Dim datTomorrow As New NotesDateTime(Cstr(Now))
Call datTomorrow.AdjustDay(1) And it's only two lines of code... but there's a way to do it in one by performing the adjustment immediately in the instantiation. LotusScript actually treats each date as a Double. The integer portion
is the date (the number of days since 12/30/1899) and the fraction
indicates the percentage of the day. Hence, if you convert Now to a
Double instead of a String it'll return something like 39665.7083333333
( Cdat that and Cstr it, and you'll get "8/5/2008 5:00:00 PM" ). As a result, you can add/substract the number of days you want to adjust, convert the result to a scalar date, and then a String... then pass that into the NotesDateTime constructor and by the time the object is initialized it already has the desired value:
Dim datTomorrow As New NotesDateTime(Cstr(Cdat(Cdbl(Now) + 1)))
Dim datOneWeekLater As New NotesDateTime(Cstr(Cdat(Cdbl(Now) + 7)))
Dim datLaterToday As New NotesDateTime(Cstr(Cdat(Cdbl(Now) + (1/24)))) Enjoy.
|
Quick tip: shorthand date adjustment in LotusScrip...
|
Thanks for all the feedback on my recent ramblings regarding LotusScript event binding. Just one more post on this and I'll leave it alone for a while. Both Thomas Bahn and Devin Olson chimed in on the last article in this series, and Peter Presnell posted a great article about compensating for weaknesses in LotusScript's OOP model, all of which prompted some useful mods to the framework. If you've already downloaded it, you may want to snag a fresh copy.
Thomas suggested that, instead of calling each bound Sub recursively with stack trace checking to prevent infinite recursion in cases where the event handler has not been overridden in the derived class... just bind the event to a delegate function that, in turn, calls the actual event handler. This results in a bit more code within the framework classes, but since the structure is such that you won't need to modify those classes again until new events are added in future versions of Notes, I'm perfectly fine with that as a tradeoff for avoiding recursion altogether. Don't worry, we'll find another excuse to use Nathan's code locking approach.
Devin's comments and Peter's article both provided insight into forcing (at runtime, at least) methods and classes to be treated as abstract, and, as such, overridden and derived, respectively. That was a bit of a mouthful, so perhaps it would be simpler to just show you the most basic of the EventBinder child classes in its current form:
Public Class TimerEventBinder As EventBinder
Public Sub New (Source As NotesTimer)
Dim classname As String
Let className = Typename(Me)
If (className = "TIMEREVENTBINDER") Then
Error ERR_ABSTRACT_INSTANTIATION, MSG_ABSTRACT_INSTANTIATION & classname
Exit Sub
End If
Set Me.context = Source
End Sub
Private Function bindEvent (Byval eventName As String, Source As Variant)
Select Case Lcase(eventName)
Case "alarm":
On Event Alarm From Source Call delegate_Alarm
Case Else:
Error ERR_UNSUPPORTED_EVENT, MSG_UNSUPPORTED_EVENT & Ucase(eventName) & " in class " & Typename(Me)
|