Archive for January, 2005

01.31.05

An Object By Any Other Name Would Still Do What?

Posted in Uncategorized at 11:05 am by UnwashedMeme

We’ve been programming in Javascript for a little bit now. My current favorite
feature of Javascript is its wonderful behavior of “Everything is an Object,
unless it isn’t.” If the language were to do automatic boxing and unboxing I
think it would work out a lot better.

One place this is an issue is when dealing with the ‘if’ construct,
as Russ previously
mentioned
. The key thing to remember is that it is just an ’isNull’
check.

var s = new String(”")
var n = new Number(0)
var a = new Array()
if(”") print(’foo’); else print(’bar’);
bar
if(s) print(’foo’); else print(’bar’);
foo
if(0) print(’foo’); else print(’bar’);
bar
if(n) print(’foo’); else print(’bar’);
foo
if([]) print(’foo’); else print(’bar’);
foo
if(a) print(’foo’); else print(’bar’);
foo

If you found the last one confusing, remember that Array is not a primitive
type in Javascript, it is always an object. The [] is just some syntactic
sugar.  Once you know all of this it isn’t to bad, just not very clear.

It is also annoying when you want to know where to call a function. Is it a
property of the object or just some disembodied function elsewhere.

new Number(NaN).isNaN()
TypeError: (new Number(NaN)).isNaN is not a function
isNaN(NaN)
true
isNaN(new Number(NaN))
true
NaN == NaN
false 
typeof(NaN)
number

So NaN is a bit of a special case, but in my experience so far Javascript has a
number of these quirks.

I haven’t seen very much good writing about prototypical inheritence. Mathew
Morgan put together some good information about
Programming with Prototypes
.

01.25.05

MSSQL Disembodied Users

Posted in Uncategorized at 10:17 am by UnwashedMeme

When you are backing up and restoring databases from one Micrsoft SQL Server to another, it is not uncommon to end up with a user on the new server associated with the database but has not login on the server. The way to give the user a login is to:

  1. Open Query Analyzer to the database in question.
  2. SELECT * FROM sysusers
  3. Find the user in question from the list.
  4. EXEC sp_addlogin 'Username', 'password', 'defaultDatabase', 'us_english', 0x0123456789ABCDEF0123456789ABCDEF
    • The last parameter is the sid of the user found in steps 2-3

It works for me at least.

01.20.05

OOP take 2

Posted in Uncategorized at 1:55 pm by UnwashedMeme

I posted a while back about my distaste for OOP. My frustration there was largely directed at the different Microsoft groups that didn’t work together, and you can have that whether following OO methodoligies or not.

Peter Lount wrote a pretty good response. One of the things he points out is how difficult it is to come up with a single defininition of an object, different groups need the object to model different things. The Office Extensibility group and the .Net windows forms designers probably wanted the menubars to do slightly different things.

OOP Is Much Better in Theory Than in Practice By Richard Mansfield is a good critique of OOP at least as done by Java/C#. Russ thinks that this is much less of an issue for langauges like Javascript, where everything is an object but nothing is static. Probably true to some extent, but I like Mansfield’s claim of OOP as a clerical function.

Choose Python

Posted in Uncategorized at 10:16 am by UnwashedMeme

Choose Python

01.18.05

That Yummy FreeSoftwareFeel: log4net Edition

Posted in Uncategorized at 7:10 pm by UnwashedMeme

So a little bit back Ryan wrote an article about
setting up log4net
, as well as doing the grunt work of getting
it into our development environment. As we are getting used to it though,
I found that basic configuration to not be good enough. Here are the
improvements.

The current project I’m working on in ASP.Net is very user centered; I want
every log message to also record which user is making that request. This
is what the Nested Diagnostics Contexts (NDC) are designed to accomplish. So I
modified the event handlers in the Global.asax.cs file.

protected void Application_AuthenticateRequest(Object sender , EventArgs e) {
   if ( Objects.User.Current != null )
      NDC.Push("UserRequest: " + Objects.User.Current.Email) ;
   else
      NDC.Push("No User is logged in.") ;

}
protected void Application_EndRequest(Object sender , EventArgs e) {
   NDC.Pop() ;
}
			

Now every log entry will include who the logged in user (or nobody). Weee!

One more thing: I was tired of typing the location of the message into the
message whenever I created a log entry. log4net is capable of recording the
code location for you automatically for a non-trivial performance hit. As I
currently use it though, I am primarily making log entries when some
odd/error condition has occurred, and not very many log entries are recorded
from normal use. As this project is also still in development  I’m
not concerned about the performance penalty right now.

Getting log4net set up to record this though turned out to be rather annoying.
The PatternLayout system is built so that certain keys are converted to usefull
data. However the
log4net manual
doesn’t say what those keys are. The
mailing list archive on SF
had some information, but overall not a
terribly good reference. This
Quick Start to Using Log4j
was a bit more useful. Fortunately they are
the same between log4net and log4j (one of the things the mailing archive
confirmed for me). Here are the ones I wanted: 

  • %C - Fully qualified class name
  • %M - Method name
  • %F - File name
  • %L - Line number
  • %l - Shortcut for %F%L%C%M

The other trick was getting to them to go into the database. As Ryan showed
previously we are putting this information into a database through the
ADNetAppender. When configuring this you specify the DB CommandText to be used
to make a log entry, and you can define parameters to be available in that
command text. For a larger example see Ryan’s
walkthrough
.  I thought it would just be a matter of defining a
couple new parameters, which it was, but it turned out the new parameters
needed to have a different syntax. So whereas the message parameter is defined
like:

<parameter>
   <parameterName value="@message" />
   <dbType value="String" />
   <size value="4000" />
   <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%m" />
   </layout>
</parameter>

The ClassName parameter needs to be defined like:

<param name="Parameter">
   <param name="ParameterName" value="@ClassName" />
   <param name="DbType" value="String" />
   <param name="Size" value="512" />
   <param name="Layout" type="log4net.Layout.PatternLayout">
      <param name="ConversionPattern" value="%C" />
   </param>
</param>

WTF?!? Why the two different syntaxes? When I tried to declare the ClassName
parameter similar to the message parameter, it would just use the message value
for each of the new parameters… yes I did check that the ConversionPattern
values were set correctly. It didn’t work until I used this alternate
syntax, at which point it worked perfectly. The original syntax comes
from the example
configuration files
 section of the log4net
documentation. Elsewhere they use the alternate syntax.

You’ve gotta love that gem of XML too, <name>Value</name> just
wasn’t verbose enough. Because, you see, this is a <param
name=”Parameter”> we are defining!

I do like log4net and I’m glad it’s there, good job developer people for
making a good, free, open, logging solution. But seriously, WTF?

01.12.05

Powerpoint isn’t very powerful

Posted in Uncategorized at 11:50 am by UnwashedMeme

Powerpoint

  • Use Bullets
    • They can even be nested
    • More bullets: Isn’t this neat?
  • Slide templates don’t allow you to put much information.
    • I would be out of space already

Examples


Enough of that.

I thought I had read Tufte’s essay a while back, but when I went searching for it again it seems that he has never posted it online and I haven’t bought it yet. I know I read a similar one at least. The main idea is that the Powerpoint format does not lend itself to presenting complex information. I know that when I have tried to give slide based presentations like this, I had to split interrelated information onto several different slides and then constantly switch back and forth. Not very good for comprehension.

My brother gave me another of Tufte’s books for christmas. The Visual Display of Quantitative Information. I haven’t dug into it yet, but I anticipate a good read. Displaying lots of information in an intelligent manner is something that we have to deal with regularly. The client wants to see all the data at once, but the screen can’t be ‘complex’.