Archive for December, 2004

Nullable value types

I’ve been playing around with c# 2.0 for awhile now. 
As a side project, and to give me something to implement in Visual C# Express, I
was planning on rewriting the o/r mapper/data access objects that we use at
work.  At first I was really excited to use generics to
greatly simplify our database collection classes, and so far the generics have
been great, I’ve reduced much of the code, and I don’t have to use nearly as
many boxing operations.

An annoying thing about mapping database values to language
values, is that fields in the database can be null, whereas in c#, a null value
would make no sense.  An int for example, you never say “int n = null;”,
but you can certainly have a null value in the database for an int field. 
So while I was happy to use generics, I was just as excited to learn that in c#
2.0, MS has implemented nullable value types. What that means is that you now
CAN write something like “int n = null;”, however the syntax is actually “int? n
= null;”.  The way that nullable types work is actually based on generics :-) .  There is a new struct in c# called Nullable<T> where T is the
type of the value that you want to store.  The syntax I wrote previously is
simply syntactic sugar for this struct. Eric Gunnerson has a good post
about nullable types, and he ought to know, he is a former member of the c# team
at Microsoft.

Some people may not like this as a solution to the database
mapping problem, but I definitely like it, because now, rather than having to
define some default value to set in case of a null database value, I can simply
set the int to null.  I like this approach better because it lets you know
exactly what was in the database. It will cause some more null
checking elsewhere in the application, but I think its worth the extra
effort.

Img src attribute getting replaced

I have a repeater that looks something like this:

<asp:Repeater>
<headertemplate>…</headertemplate>
<itemtemplate>
<tr>
<td>….</td>
<td><img
src=”../../images/myimg.gif” height=”16″ width=”16″ id=”img1″ runat=”server”
/></td>
<td>….</td>
</tr>
<footertemplate>….</footertemplate>
</asp:Repeater>

I
have an event handler on the ItemCreated event of the repeater, so that I can
check a value and put a javascript onclick event on the image if the value
passes the test.  This is all well and good, I view the page, check the
source and I see my onclick event attached to the image.  The problem is
that the src attribute has been changed.  It seems that when .net renders
the img, it removes one set of the parent path.  So the src on the page
looks like this:

<img src=”../images/myimg.gif” height=”16″ width=”16″
id=”img1″ runat=”server” />

So now my image has a broken link. Anyone know why,
WHY, would my image src attributes get changed??

I worked around the problem by removing the img element
completely, making the table cell a server control,  checking the value,
and then just writing the html literal string into the InnerHtml property
of the cell; this all works fine, but its annoying to have to waste time finding
this out.

 

Possible MS response?

I love this idea from Stephen
O’Grady
(via Scoble),
Microsoft definitely has a chance to surprise people here, they should take
advantage.

Lhotka on SOA

Rockford Lhotka has a great
post
about SOA and his opinions about Indigo and the future.  This
is probably the most interesting and informative writing about SOA that I’ve
come across. He talks about SOA and how it uses passive data as opposed to an
objected oriented system where the data is tied to the actions that are
performed on it.  He favors the object oriented method, because of the
clean, organized code that it can produce, and the tight coupling of the data
rules to the actual data.  I have to agree; by including the functions that
act on the data, with the data, you can easily create a single interface to the
data, rather than have a function library like you would in COBOL.  I also
believe that its easier to exhibit the intent of the code when its
been written in an object oriented fashion, making life a little easier on
the person maintaining your code.

SOA seems to be the hip, sexy thing to be into these days,
kind of like how XML was stylish a few years ago, when people would use XML just
to say they used XML.  Towards the end of his post, Rockford alludes to “The really cool ideas – the
ones with the power to be emergent”, and how they are not being
recognized, I’d love to see another post going into detail about those cool
ideas.

User Controls and javascript

I have wondered about this for a long time, but have also long since accepted the circumstances.


Why, when I place form elements on a user control, does it have to append “UserControlId_” to the id
of the element and “UserControlId:” to the name of the element? This is really annoying for custom javascript that is written for these elements and form submissions. Once you realize that
this happens, its not that difficult to define a javascript variable and append it to the beginning of all the elements that
you are using, or parse the form collection on the codebehind before you use the posted data, but it can still be frustrating. I was hoping that this behavior would be removed when master pages came out
with asp.net 2.0, but alas, after working on a side project using master pages, I see that this still occurs.

Does anyone know why this is neccesary?

.Text Source

I’m interested in playing around with the source for .Text, but the source isn’t available on GotDotNet anymore.

Does anyone know where I can get a copy? thanks

Firefox Award

I declare Foxy Tunes to be my Firefox extension of the day, this thing is sweet! You can manage a multitude of different players from it, and it shows the current track in the status bar, awesome!



What are other people’s favorite extensions?

Another 2 cents on desktop searching….

I have to agree with Brendan that while all of these new
desktop search applications are cool, I already know what I have on my
desktop.  I cannot recall more than a few instances of times where I knew
that I had something but couldn’t find it, except for emails.  If MS just
had a better integrated search in Outlook, I would be happy.  I don’t like
having to run a separate application that takes up my precious taskbar space and
also slows down my machine.

I’m wondering why it took so long for decent search
capability to be available?  Was it just because of lack of
competition?  This appears to be the case. They already have the
indexing service, so they could create an index of users’ files, if they just
put some options into that service that allowed users to specify which file
types get indexed, I would think a lot of the work would be done.  But not
until only a few months ago did MS take searching seriously, and they were still
late to the party, a party started by Google.

WinFS delayed

Frans Bouma reacts to the news that WinFS
will be
delayed for 1,989,342 more years
(actually about 2 but it seems longer, doesn’t it?).  This is too bad, I
was definitely looking forward to such a radical change in the way filesystems
are structured, I think WinFS is terribly intriguing because it appears to be a
complete rework of something that hasn’t gotten a whole lot of
attention.

Frans believes that WinFS has been given low priority over
other projects, and I would have to agree.  It seems that Microsoft has
done a poor job of PR for this particular project.  WinFS was hyped as the
solution to many filesystem woes, notably the ability to search your
hard drive.  By telling us that it would be in Longhorn, they set
themselves up for disappointment. Now they say that it won’t even make it into
the Longhorn server version slated to be released in ‘07.  Even though
Microsoft can weather the storm that occurs by slipping release dates, this
doesn’t help their image, especially among developers and IT
professionals.

Google trumped Microsoft by releasing a desktop
search tool
that searched users’ hard drives much
better and MUCH faster than the built-in Windows search, and Google didn’t need
a new filesystem; it must be embarassing when a competitor improves your own
product better than you can yourself.  You can say what you want about
Google’s thin web client interface, it gets the job done.  Since a huge
goal of WinFS was to improve searching, and then along comes a free search
tool that accomplishes the goal, I’m sure Microsoft had a little priority
rearranging.  I think Frans nailed it by asserting that Microsoft had to
react quicker than WinFS would allow them to, and had to release something, thus
the major slippage of WinFS.

At this point, I have to almost wonder if WinFS will ever
come to fruition, or will it go the way of
Hailstorm? A lot can change in 2 more
years, and if the tools that are released in ‘05 are good enough, I think its
possible that we will never see WinFS.

Design Patterns Book

I’m looking for a good book on design patterns, I
was at
Barnes
& Noble
this morning and I was paging through
Head First Design Patterns and thought
that it looked pretty interesting.  So does anyone have a great book that
they know about?  Drop me a line with any recommendations,
thanks