Why Not Use Reflector?

Why Not Use Reflector?

I whined about the source for Script# not being available at the beginning of this post.  One brilliant reader who decided to be chicken and use false email and name, misinterpreted that as "I can't get the source for Script#".  That was not what I said.  I said the source was not available.  Codeplex is supposed to be Microsoft's answer to SourceForge.net.  Here's the blurb at the top of Codeplex site declaring the purpose of the site:

So Script# doesn't have any source, why not use Reflector? This is is the most annoying part about it, I can use Reflector! If I can use Reflector, why is the source not available on Codeplex(remember that blurb, "open source" was in there).  No source sure seems more like closed source to me...

How Do You Programmatically Generate JavaScript?

I'm playing around with some different techniques of generating javascript with C#.  No, I'm not creating my own Script#; which, by the way, i think it should be a rule that no one should be allowed to host software on codeplex without providing the sourcecode-see here for the script # source code - ya, there's nothing there, soooo lame.  Here's some code I need to generate for various reasons from C#:


function save(){
  if ($F('Name').replace(/ /,'').length == 0){
    alert('Please enter the name.');
    $('Name').activate();
    return;
  }
}

1
2
3
4
5
6
7

StringBuilder

Anywho.how do you generate javascript through code? StringBuilder? OK.  But that usually means alot of typing and is error prone.  Also it can be hard to read. Here's one way of using the StringBuilder:  The problem with this is that your have to remember to include the tab characters and the end of line characters, which is annoying, i don't want to have to remember that crap.


StringBuilder js = new StringBuilder();
js.Append("function save(){\r\n");
js.Append("\tif ($F('Name').replace(/ /,'').length == 0){\r\n");
js.Append("\t\talert('Please enter the name of the project.');\r\n");
js.Append("\t\t$('Name').activate();\r\n");
js.Append("\t\treturn;\r\n");
js.Append("\t}\r\n");
js.Append("}\r\n");

1
2
3
4
5
6
7
8

StringWriter

Here's a StringWriter example.  We've excluded end of line characters but still have the stupid tab characters, lame.


using (StringWriter js = new StringWriter())
{
  js.WriteLine("function save(){");
  js.WriteLine("\tif ($F('Name').replace(/ /,'').length == 0){");
  js.WriteLine("\t\talert('Please enter the name of the project.');");
  js.WriteLine("\t\t$('Name').activate();");
  js.WriteLine("\t\treturn;");
  js.WriteLine("\t}");
  js.WriteLine("}");
}

1
2
3
4
5
6
7
8
9
10

ScriptWriter

Ya, stoopid name, but this is my attempt at eliminating the need handle formatting myself and end of line characters, as well as semi colons at the end of javascript lines(yes, not required but I prefer them), and curly braces in their appropriate places.


using (ScriptWriter script = new ScriptWriter())
{
  script.CreateBlock("function save()");
  script.CreateBlock("if ($F('Name').replace(/ /,'').length == 0)");
  script.WriteLine("alert('Please enter the name of the project.')");
  script.WriteLine("$('Name').activate()");
  script.WriteLine("return");
}

1
2
3
4
5
6
7
8

CreateBlock notifies the code that we're going to basically indent and create a new block of code that's surrounded by a statement and open and close braces.  I started going down the path of creating code nodes, similar to the CodeDom, like here's a block, and it contains lines, some of the lines are other blocks, etc.  But that didn't feel right, actually it felt like I was trying to recreate the javascript dom.  ScriptWriter doesn't feel super comfortable right now either, but this is a first stab.

Click here to view the source.

Ugh...I Hate Cleaning

Lasagna

My brother Tim went to college and at some point worked at an Italian restaurant.  While there, not only was he taught how to cook some dishes, he was also taught how to cook.  The golden rule that he was taught was that a great chef never makes a mess.  Tim taught me how to make one of the few "dishes" I can make today, lasagna.  He taught me that after using an ingredient, you put it away.  If you notice some bits of stuff lying around, like cheese or noodle bits or anything considered garbage, scoop them up as soon as you notice to stay ahead of the mess.  Finished with a bowl? either clean it or put it in the dishwasher.  Simple.  When it's time to put the lasagna in the oven to cook, there is no mess to clean up.

Scrambled Eggs

My wife Anja and I are different breeds when it comes to cooking, nothing elaborate, just stuff like fixing scrambled eggs or whatever.  Anja makes scrambled eggs by basically taking out all ingredients, mixing everything up, and leaving all of the dishes and ingredients out.  The benefit? We eat maybe a little sooner than later, BUT when we're done eating, there's a big ass mess to clean up, and did i mention that I hate cleaning?

I make scrambled eggs similar to how I make lasagna, only a little more OCD-ish.  Basically, when I'm done making the scrambled eggs, there isn't anything to clean except for the pan and spatula used to cook the eggs.  I didn't make a mess(not much anyway), and when I'm done? There's pretty much nothing to clean up, it's already done.

OK, Great, Now What About Software???

My philosophy on software development goes something like this, if you don't make a mess, you won't end up with a mess.  A similar belief of mine that usually evokes the response of laughter goes something like this, if you don't create bugs in your code, you won't end up with bugs in your code.

So, do I make messes and bugs in my software? YES.  It happens, for one reason or another it happens, BUT, and this is a big BUT, I'm capable of looking back and identifying what led to the mess and/or bug, and attempt to learn why it happened and figure out a better solution for the next time around.  As I get better at identifying things that caused previous messes and bugs, I get better at starting off on the right foot, not recreating the same stupid bugs over and over.

Bugs Are Not Respected Enuff To Get Postponed!

Bugs are like the little things that accumulate while cooking, ingredients, dirty bowls, all they do is contribute to a big pile of shit that you'll be responsible for cleaning up when the project's done.  It's not fun, I'm pretty sure if you ask any developer creating new code today if they would prefer fixing bugs over creating new cool ass code, the answer will not be fixing bugs.

So if there are known bugs, fucking fix them NOW, not later, cuz waiting is just going to make that pile of shit that needs to be fixed a little bit bigger and you as the developer a little more depressed.

Slayer Lives

OK.  Slayer is up.  It's running 64 bit Ubuntu 8.04, Hardy Heron.  I'm using my old machine, a dual core AMD 4200.

I am a linux NOOB big time.  I have been for years and always go in spurts of Linux here and there but this is cool.  With hardware so cheap and Linux getting so much better(for the windows dorks like me), I'm starting to really have fun with this stuff.  I'm writing this blog post from the new linux install too.  Need to verify how this post looks in IE from Linux? Check it out, vmware player, running 64 bit windows server 2003 and IE 7 on Ubuntu.

One cool thing is that the vmware image i'm running is a 30 gig file running on Deathangel, I set up a share, believe it or not(I almost know what I'm doing on Linux), using Samba, and vmware player had no issues about loading up the image from across the network.

 
Author: , 0000-00-00