Never Ask an Engineer for the Time

by Nick Wednesday, May 30, 2007 8:57 AM

Unless you want to learn how to build a watch.

Blogging PSA

by Nick Friday, May 25, 2007 5:03 AM

This obviously doesn't affect me, but does potentially affect many of the other blogs I read:

Security analyst David Kierznowski shocked bloggers yesterday with a survey showing that 49 out of the 50 WordPress blogs he checked seem to be running exploitable versions of the widely used software. He said, 'The main concern here is the lack of security awareness amongst bloggers with a non-technical background, and even those with a technical background.' Mr Kierznowski also uncovered recent vulnerabilities in WordPress plugins that ship by default with the software, adding: 'WordPress users developing plugins must be aware of the security functions that WordPress supports, and ensure that these functions are used in their code.'

So if you run WordPress on your own domain, check your version and upgrade if you are running anything less than 2.0.10 or 2.2.

What is a Web Site?

by Nick Thursday, May 17, 2007 12:48 PM

It's this thing you can look at that comes to you using a series of tubes!

A British judge admitted on Wednesday he was struggling to cope with basic terms like "Web site" in the trial of three men accused of inciting terrorism via the Internet.

Judge Peter Openshaw broke into the questioning of a witness about a Web forum used by alleged Islamist radicals.

"The trouble is I don't understand the language. I don't really understand what a Web site is," he told a London court during the trial of three men charged under anti-terrorism laws.

For God's sake... even my mother knows what a website is.

Real World

by Nick Saturday, May 12, 2007 10:56 AM

This is interesting.  I'm currently reading a Self-Paced Training Kit book for an exam towards my MCPD.  It's talking about different features in .NET 2.0 (which seems kind of boring since I really already know all of this).  However, what is good so far about this book are the occasional interludes of "Real World" information thrown in by the authors that break from the normal "Oo Ra Ra, Go Microsoft" information.  One of them is talking about Generics (a feature that I love) which shocked me:

I haven't been able to reproduce the performance benefits of generics; however, according to Microsoft, generics are faster than using casting.  In practice, casting proves to be several times faster than using a generic.  However, you probably won't notice performance differences in your applications.  (My tests over 100,000 iterations took only a few seconds.)  So you should still use generics because they are type-safe.

Huh?!  Granted, the type safety aspect is a huge benefit.  However, I can't tell you how many times I've heard from Microsoft people about the huge performance benefits.

To be honest, I always suspected a problem in that respect, but I always thought it was me.  I had written a .NET 1.1 library a while ago that implemented different types of Binary Search Trees and a Skip List.  When .NET 2.0 came out, I decided to make a 2.0 version using Generics as an exercise to learn the new feature.  When I did some timing comparisons, I found that it was either a little slower, or largely the same depending on the test.  I always figured it was something in my implementation, or my timing code.  Maybe it wasn't me after all.

Why Yes, I Am a Geek

by Nick Thursday, May 10, 2007 1:29 PM

An actual conversation at work:

Coworker:  Do you remember that episode from Star Trek where those little guys came on the ship, and they only spoke in binary, and everything they said was just coming out in a gibberish of bits?

Me:  Sadly, I do remember that episode.  How cliche is that?

When Software and Politics Collide

by Nick Tuesday, May 08, 2007 8:24 AM

This quote is too perfect... too funny... and applies equally well to both my personal blogs.  I just don't know where to put it, but I have to share it.  From Nathaniel Borenstein:

It should be noted that no ethically-trained software engineer would ever consent to write a DestroyBaghdad procedure. Basic professional ethics would instead require him to write a DestroyCity procedure, to which Baghdad could be given as a parameter.

Via Coding Horror who has many other fantastic quotes to share.  My personal favorite quote is from Michael Sinz:

Programming is like sex, one mistake and you have to support it for the rest of your life.

Fun With Reflection... Reference vs Value Types

by Nick Monday, May 07, 2007 9:20 PM

So here is an interesting little quirk I found regarding Reflection in .NET.  I was writing a serialization library that was capable of reading and writing to a CSV file format, and also to a fixed width file format.  The project I was working on had various CSV and Fixed Width formats to deal with, so we wanted a nice and generic library to read and write with.  Moreover, the code I was replacing basically just parsed everything into a string, and then there would be tons of logic that simply indexed into a string using a constant to represent the position in the row.  We wanted each record in the file to be read into a strongly typed structure.

I decided to make use of Reflection so that you could create a data structure that looked like this:

[TextSerializable]
public class Person
{
    [TextField(0)]
    public string Name;

    [TextField(1)]
    public int Age;

    [TextField(2)]
    public DateTime DateOfBirth;
  }

And then easily read it in by doing this:

TextReader reader = new StreamReader( "TestFile.csv" );
CSVSerializer<Person> ser = new CSVSerializer<Person>();
Person p = ser.Deserialize( reader.ReadLine() );

Sounds pretty easy right?  But what if you want your target data type to be a struct instead of a class?  Should be pretty easy right?  As it turns out, there is a little known quirk in how you use reflection to set Property and Field values that makes a big difference due to boxing.

The serialization class that I wrote uses reflection to find all the Fields and Properties that have been marked with the TextField attribute.  Then during the deserialization process, it uses the PropertyInfo.SetValue (or FieldInfo.SetValue) method to set the value on the newly created target type.

Here is the trick.  You have to know whether the target type if a class or a struct.  If it's a class, then you can pass in an object reference.  If it's a class, then you have to store the variable in a ValueType variable.  Otherwise the structure will be boxed, and during the boxing/unboxing process, the value will be lost!

It's weird... you call the exact same SetValue method... there is not even a special overload that takes a ValueType vs Object type.  However, it makes all the difference in the world.  Here is part of the code from the Deserialize method.  TargetType is the generic type that gets passed in during the declaration (in the above example it was Person).  I stored the Type variable in _type.

TargetType returnObj = new TargetType();
            
ValueType  returnStruct = null;
if ( _type.IsValueType )
{
    object tempObj = returnObj;
    returnStruct = (ValueType)tempObj;
}
// Parsing code here
if ( _type.IsValueType )
    AssignToStruct( returnStruct, fieldObj, attr.Member );
else
    AssignToClass( returnObj, fieldObj, attr.Member );

And here is AssignToClass and AssignToStruct:

private void AssignToClass( object obj, object val, MemberInfo member )
{
    if ( member is PropertyInfo )
        ( (PropertyInfo)member ).SetValue( obj, val, null );
    else if ( member is FieldInfo )
        ( (FieldInfo)member ).SetValue( obj, val );
    else
        throw new TextSerializationException( "Invalid MemberInfo type encountered" );
}

private void AssignToStruct( ValueType obj, object val, MemberInfo member )
{
    if ( member is PropertyInfo )
        ( (PropertyInfo)member ).SetValue( obj, val, null );
    else if ( member is FieldInfo )
        ( (FieldInfo)member ).SetValue( obj, val );
    else
        throw new TextSerializationException( "Invalid MemberInfo type encountered" );
}

Notice how they are identical, except for the type being passed in?  It's absolutely crazy making to have this copy and paste code, but it's necessary.  The other crazy making part is that FieldInfo and PropertyInfo don't have a common base which has SetValue in it.  For whatever reason, all languages in .NET treat Properties and Fields as identical syntactically, but they are completely different reflected.  More copy and paste madness.

Make It Stop!!!

by Nick Monday, May 07, 2007 4:32 AM

The floor where I sit at work is shared between developers, and call center personnel.  In an effort to drown out the call center from the developers, and likewise drown out the developers to the call center folks, they recently installed white noise generators in the ceiling.  Today it sounds like they turned up the volume.

It's driving me insane!  It's like having a television over your head where you only hear the snow coming through because the cable is out.  I'd rather listen to the call center people (which I can still actually hear somewhat).  They've simply replaced one type of noise with another.  Except this noise is much more distracting, and it feels like its burrowing deep into my subconscious.

I can't work.  I can't concentrate.  I'm getting a headache.  I've already yelled at someone this morning.

I think I've finally discovered what causes people to go postal at work.

Update:  I've just been informed that the volume increasing is by design, and that they're going to bump it up again next week.  They're supposedly doing this incrementally so that we get used to it gradually.  I already can't work... I can't imagine how much worse it will be next week.

I was feeling kind of depressed at work last week (when the volume was lower), and couldn't put my finger on it.  I feel worse today... and this has to be the reason.  I'm also definitely more on edge and moody too.  I am seriously kicking myself for forgetting my MP3 player.  But you know, sometimes when I work, music can be distracting.  But now my choices are going to be distracting music, or painful white noise.  What kind of choice is that?  Why would a company purposefully do this to it's employees?!

Update II:  After a round of complaints by everyone, they've turned the volume back down to the same level as it was last week.  So now the headache is much more mild, and at least I can concentrate again.  Of course, I can still hear the call center folks on the other side of the hall, which begs the question... why bother with the white noise at all?  If the volume has to be at annoyingly high levels to drown out the call center, then what's the point?

Never Stop Learning

by Nick Tuesday, May 01, 2007 12:18 PM

One of the things they told us at Engineering School was that they weren't just teaching us "stuff", they were teaching us "how to learn".  You can never stop learning.  New technologies, languages, frameworks, methodologies are always coming around.  Either you keep up, or you fall behind.

I like to think that I've done a good job at keeping up.  My resume is filled with a vast array of TLA's that have shown that not only do I give lip service to learning, but that I've done it, and applied to projects.  I've worked on C++ with MFC, then COM and ATL, and now .NET.  Now it looks as if something big is coming around the corner.

Time to start learning again.

About Me

Nick Schweitzer Nick Schweitzer
Wauwatosa, WI

Contact Me
I'm a Software Consultant in the Milwaukee area. Among various geeky pursuits, I'm also an amateur triathlete, and enjoy rock climbing. I also like to think I'm a political pundit. ... Full Bio

Community Involvement

Twitter

Archives

Flickr Photos

www.flickr.com
This is a Flickr badge showing public photos and videos from Nick_Schweitzer. Make your own badge here.

Standard Disclaimers

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2017 Nick Schweitzer