October 2003 - Posts

30 October 2003
doh...
So, there you are...sitting somewhere with the woman of your dreams...or perhaps about to win your the game you've been playing for 48 straight, whatever...just plug in your dream situation. then it hits you...FUCK, I WROTE THAT CLASS WRONG!!! that is just what happened to me, except i was in the middle of a seinfeld episode i had never seen before (yeah, i am lame) so, i wrote that singleton object that exposes all the elements of a config file via static properties...DOH! that was the wrong way to do it! erase all of the static keywords in AppConfiguration, and replace any calls to the singleton class w/ AppConfiguration.Getconfig (the previous way was simply AppConfiguration.[whatever]... live and die by the code j Read More...
30 October 2003
Ramblings...
how are we american programmers getting displaced by thousands by foreigners? if they program in VB, they almost have to learn the entire english language just to use it! ok, that was a cheap shot...but still... come on america...step it up! where else can you not work for pennies a day living in a shanty and be grateful for every second of it! whatever j Read More...
Filed under:
29 October 2003
T-SQL nightmares...
So, i've been given the task of scrubbing some data for a group at my work. apparently they have about 50 records w/ either invalid zip codes or invalid SSN's. writing regular expressions in C# is a snap, however i have to load this data into an excel spreadsheet, so it would be a lot easier to try and validate the data on the server with T-SQL. have you ever tried to do string parsing with T-SQL? there is absolutely no way to check and see if it's going to work until you hit the little green play button in SQLQA... this is gonna be a fun one... j Read More...
29 October 2003
Follow up for a previous post...
I had previously posted a blog on 10/28 about how to get a class library to dynamically find it's own config file...then i realized that i didn't give any instructions on what to do next as far as loading that config file into some sort of object so that your application can use it! Personally, i would load the configuration file into a singleton object. per msdn documentation, the C# code for this would be: class Singleton { public static Singleton Instance() { if (_instance == null) { lock (typeof(Singleton)) { if (_instance == null) { _instance = new Singleton(); } } } return _instance; } protected Singleton() {} private static volatile Singleton _instance = null; } i personally find this a bit wordy and complex for what we are really trying to accomplish here. we need one object to share common properties with any subscribing assemblies, for the most part this information isn't going to change, so why waste round trips instantiating a new object each time your assembly needs a property... Read More...
29 October 2003
Bedtime thoughts...
if you are going to concat more than 2 strings, consider using a StringBuilder object...or just use the code below to obtain a nicely formatted string: public static string BuildStrings(params string[] stringsToBuild) { string delimiter = " "; // this will be the return string string builtString; // use a StringBuilder as the internal mechanism to build the string StringBuilder localBuilder = new StringBuilder(); // loop through each string passed in and add it to the string to build foreach(string stringToBuild in stringsToBuild) { localBuilder.Append(delimiter); localBuilder.Append(stringToBuild); } builtString = localBuilder.ToString(); return builtString; } Read More...
28 October 2003
Tip of the day...
VB.NET supplies the "Optional" keyword for parameters in methods, if none is supplied you can explicitely define a default value in the parameter signature. C# doesn't supply this functionality (and for good reason, it leads to lazy coding). it's good coding practice to always check the values of parameters in your components, and either throw an assertion or an exception if it's not supplied, like so: void myMethod(type myType1, type myType2...) { // check here for params that cannot be null, or "" for strings if(myType == null) throw new ArgumentNullException([message], [inner exception]...); // now check for validity of the param using regex, etc, you can't count on client code doing these checks if(myType != [some sort of criteria]) throw new ArgumentException ([message], [inner exception]...); } that being said, if you wanted to provide a default value, you can use ternary syntax to provide one void myMethod(type myType1, type myType2...) { myType1 != null ? MyType1 : [your default... Read More...
28 October 2003
Quote of the day...
The less buttons you give end users, the less shit that can go wrong. it's directly proportionate...sometimes i feel like my company should hire a herd of monkeys, they'd probably fuck up less. j Read More...
Filed under:
28 October 2003
What a day
So, today i learned the hard way that .NET class library apps don't intrinsically support .config files. after about 4 hours of head scratching i came up w/ the following bit of code that will dynamically load a config file with the same name as the assembly loading it: internal void GetConfigurationFilePath() { DirectoryInfo currentDir = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory + "\\"); _pathToWorkingDirectory = currentDir.FullName; //loop through all assemblies currently loaded foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies()) { string asmName = asm.CodeBase; int index = asm.CodeBase.LastIndexOf(@"/"); string part = asmName.Substring(index + 1); //now compare that substring to the name of any config files found in the current directory foreach (FileInfo file in currentDir.GetFiles ("*.config")) { if (part.Trim().ToLower() + ".config" == file.Name.Trim().ToLower()) { _configFileName = file.FullName; } } } } it's actually quite simple once you look at it.... Read More...
28 October 2003
Welcome to my Weblog!!!
i sure as hell wasn't going to pay for one, so i built (read: hijacked) my own. we'll see how it goes, i am pretty good at breaking shit. The purpose of this blog is for me to share just how little i have learned i know about coding and .NET technologies...each day i learn a little bit more... more to come! j Read More...
Filed under: