Category Archives: Programming and Software

Sketchburger

http://www.computerworld.com/printthis/2004/0,4814,97224,00.html

Going down fast
Slashed resources and impossible demands have caused IT morale to disintegrate.

News Story by Julia King

NOVEMBER 08, 2004 (COMPUTERWORLD) – Skeptical, stressed, scared, sucked dry. This is how IT professionals feel about work these days.

Other telling words that surfaced repeatedly during more than 30 interviews and in 200 written survey responses include fear, loathing, disgust and dread.

To be blunt, IT worker morale sucks, and it’s getting bleaker by the day.

Gooey

It’s been a while, but here’s some software for dat ass.

If you develop language-localized applications, you spend a lot of time making resource files. Mostly you use ResGen to do this, which is a fine little CLI tool that does the trick.

But, CLI tools are no fun, and this is .NET we’re talking about, so here’s a little GUI for ResGen.

Unzip, edit the config file to point to your ResGen binary (usually somewhere in the .NET SDK)

Browse to your text resource file, and *poof* – generate a binary .resources file.

The tool is by no means complete or even useful, but what the hell – I need a break from webapps now and again!

Download it here: http://portfolio.vistaseeker.com/file/ResGenGui.zip

You’d laugh if you knew how easy this is to do with .NET. All you need is the System.Process classes, a simple WinForms class, and some minor text munching. Cakewalk.

P.S. you need the .NET runtime installed for this thing to run!

Nerd Alert

After the thousandth line of boilerplate database code, I decided I had had enough and it was time too look into something new.

Most multi-tier db apps these days consist of a database layer, a business object layer, and a presentation layer. The GUI and database update the business objects, so you should always have an accurate reflection of the state being modeled.

The major problem for a dev is that you have to map the DB to the business objects. Typically this involves a whole lot of diddling with type conversions as you get your programming language’s types into DB types and vice versa. The end result is nice though – you have a UI with no connection to your functionality – so if you need to turn your webapp into a full-blown OS-native application – it’s just a matter of writing a new presentation layer.

I have started to gravitate towards ORM (Object-Relational Mapping) and code generators to get through the mind-numbing CRUD and get to the fun parts.

The gold standard is Hibernate, but it’s Java and the .NET version is still alpha software.
Olero Software’s ORM.NET is fairly popular, but it appears to be abandonware which has now found a home on SourceForge.

I found a tool from France called LLBLGen which pretty much handles all the crufty filth associated with database apps. Point it at a table, click a button, and get sprocs and an object which models the table.

No more conversion of native string and integer types to DB-native types. No more dealing with NULL. No more creating and assigning parameters. You get an object, set the fields, call insert(), update(), or delete. Cake.

For simple tasks, you can use their free, one-way data tier generator. It’s a nice medium between the ORM world and the “SQL in the code” world.

Another task that I can’t stand is writing out the getters / setters (accessors / mutators) for an object, especially big ASP.NET User Control classes with 1000 form elements. Eclipse has a nice feature to let you automatically generate getters & setters from your private class vars, but VS.NET lacks the feature. Not anymore. It’s not perfect, but it works.
vsPropertyGenerator

All you devs out there writing SQL in your loosely-typed scripting language probably feel that I’m just making things too hard. All I can say is this: your apps suck.

Fun

A couple of easy sort algorithms for you. Look ma, no array subscripts! C is the shit, kiddies!


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define ELEMENTS 10
#define ARRAY_ELEMENT_COUNT(array) (sizeof(array)/sizeof(array[0]))

//type-independent malloc
void *MyMalloc(size_t size)
{
void *vp;

if ((vp = malloc(size)) == NULL)
{
fputs("Cannot allocate memory for malloc.n",stderr);
exit(EXIT_FAILURE);
}

return(vp);
}

//swap void pointers
void SwapElements(void *pa,void *pb,size_t size)
{
//temp void pointer to hold an element to swap
void *tmp = MyMalloc(size);

//use memcpy to perform the swaps
memcpy(tmp,pa,size);
memcpy(pa,pb,size);
memcpy(pb,tmp,size);

free(tmp);
}

//bubble sort implementation, fancy-style.
void BubbleSort(float *first,size_t size)
{
float *current_offset,*current,*last = &first[size - 1];
int flag_swap;

do
{
for (flag_swap=0,current = first; current {
//set a pointer to pointer to current element of array
current_offset = current;

//increment the temp pointer
current_offset++;

//compare current element and current[1]
if (*current > *current_offset)
{
//cast to void pointers and swap
SwapElements(current,current_offset,sizeof(float));
flag_swap = 1;
}

}
}
while(flag_swap);
}

//just for fun
void ShuttleSort(float *first,size_t size)
{
float *current_offset,*current,*back,*last = &first[size - 1];

for (current = first; current {
current_offset = current;
current_offset++;

if (*current > *current_offset)
SwapElements(current,current_offset,sizeof(float));

for (back = current; back > first; --back)
{
current_offset = back;
current_offset--;

if (*back SwapElements(back,current_offset,sizeof(float));
else
break;
}
}
}

int main()
{
int i;
float arrToSort[ELEMENTS];

for (i = 0;i {
puts("Input a floating point number:");
scanf("%f",&arrToSort[i]);
}

//BubbleSort(arrToSort,ARRAY_ELEMENT_COUNT(arrToSort));
ShuttleSort(arrToSort,ARRAY_ELEMENT_COUNT(arrToSort));

puts("------------------------");
puts("Output of sorted array:");

for (i = 0;i printf("%fn",arrToSort[i]);

return(EXIT_SUCCESS);
}

Tech Investors – A Blessing and A Curse

Working for a public company, I am able to see the other side of the tech investment equation. Our company needs investors to grow. But on the other hand, unhappy investors can actually hinder growth.

The problems with many individual and institutional investors are complex, but her’s a couple bullet point that can hopefully help you to spot the pitfalls and safely make money off tech stocks.

* It’s not the 70’s (or the 90’s) anymore.
There was a time, when all of a sudden, a whole bunch of companies came out of nowhere and created technologies that changed the world. The first wave of tech created the HP’s,IBM’s,Apples,Suns, and Microsoft’s of the world. Anyone sitting on those shares today is sitting on pure gold. If you are interested in trading in these kind of stocks check out this resource from SoFi

Similarly, the late 90’s internet boom saw the simultaneous birth of Ebay, Amazon, and Yahoo, which made a lot of money for a lot of people.

The danger here, is that many people seem to think that the ‘next big thing’ is just around the corner. Fact is, it’s most likely not. Technology is like any product, it takes years of slow growth and refinement before it hits the mainstream.

The key to knowing what the ‘next big thing’ is, is described in the next item.

* Be in the Know
The Internet didn’t invent itself. It grew slowly, and somewhat quietly. By the time it had hit mainstream, a mad dash was on to own a piece of these young companies.

If you had a friend in the business, you probably knew what was going on. If you had the foresight to see it’s potential, you probably did quite well for yourself.

The point here is, if you invest in tech, read the trade rags. Know what’s going on. The major media won’t be able to keep you informed. That leads us into our next point.

*Watch our for Market Trends
Analysts, journalists, and armchair brokers love trend-spotting. and Why not? It’s fun, just pick an industry, line up the charts, and watch.

The problem is, that many tech sectors, particularly in software, are not well-defined enough to be judged as a trend indicator. This is due to the great variation in the potential vs current valuation of any company at a given time.

Many investors see smaller companies with weaker bottom lines as shaky, but do not understand fundementals of the business, such as the margin on the product or the maturity of the sector.

As a result, innovators with poor margins and me-toos with identical products often dilute the trends and create misleading indicators of the value of a sector.

There is no substitute for homework, the title of our next section.

* Do your Homework
Know the facts. Know the financials, know the share dilution, know the executive track record. Call the IR people if you can. Familiarize yourself with the product. Know the history of the product, know the history of the company.

Joel on Houseware

I am in danger of becoming a Joel Spolsky fanboy. This article is amazing.

“And here’s the clincher: I noticed (and confirmed this with a recruiter friend) that Windows API programmers here in New York City who know C++ and COM programming earn about $130,000 a year, while typical Web programmers using managed code languages (Java, PHP, Perl, even ASP.NET) earn about $80,000 a year. That’s a huge difference, and when I talked to some friends from Microsoft Consulting Services about this they admitted that Microsoft had lost a whole generation of developers. The reason it takes $130,000 to hire someone with COM experience is because nobody bothered learning COM programming in the last eight years or so, so you have to find somebody really senior, usually they’re already in management, and convince them to take a job as a grunt programmer, dealing with (God help me) marshalling and monikers and apartment threading and aggregates and tearoffs and a million other things that, basically, only Don Box ever understood, and even Don Box can’t bear to look at them any more.”

How Microsoft Lost the API War

Breakdown

I finally learned how to use a visual debugger – lemme just say: “WHY THE HELL HAVEN’T I BEEN USING THIS ALL ALONG?”

I was a print-statement guy for a long time, but I can say with no hesitation: a visual debugger that can step-through code is an essential tool.

Sassy B’s ASP.NET Jambaroo

About 3 months ago I made the decision to dump “classic” ASP / VB COM in favor of Microsoft’s spankin’ new ASP.NET.

In a short while I have picked up VB.NET and C#, and become quite familiar with most of the common framework components. While there is a lot to cover, I’ll give you my overall impressions of the framework and the toolkit.

Firstly, it’s important to note that ASP.NET is a quantum leap over ASP/COM. While ASP/VBscript was/is effectively a crippled programming language for novices, .NET gives an experienced dev a lot of nice tools.

The jury is still out on whether ASP.NET really offers much over JavaBeans and JSP or PHP. Obviously these are not easy comparisons, as each has it’s own strenghts and weaknesses. I will say, without a doubt, that ASP.NET offers very little that is not already available in other web app platforms. What it does offer, however, is a bit more polish, and a bit more completeness, and a bit more ease-of-use, especially for novice web devs.

ASP.NET’s maligned and misunderstood event model is actually a nice feature, especially once you begin re-using user controls. Simply put, you can encapsulate the logic of a form in a user control, nest those controls in a page, and the aggregated events will all fire based on the parent’s events. This is very slick, and allows for some quite profound code re-use.

ASP.NET is also an interesting beast, offering a simple XML template system on top of ‘codebehind’ script. While this does a good job of separating presentation from logic, it is somewhat primitive and simple when compared to SMARTY (PHP) or Velocity / Freemarker (Java). The simplicity and ease-of-use with ASP.NET limits it’s ability to do things like dynamically load templates and nest templates. While this is possible by overriding some .NET base classes, it’s expected that ASP.NET 2.0 will have some sort of robust templating, called ‘Master Pages’.

VB.NET is an update of VB 6 and is now a completely OOP language. A lot of the nasty idiosyncracies of VB have been cleaned up. Problem is, there is really no longer a compelling reason to use VB for anything – because you have C#. Many of us seem to agree that VB.NET is the endgame plan for Microsoft to drop VB 6 support. I would guess that 90% of VB programmers will never make that leap, and will spend their careers trapped in the VB 6 ghetto Microsoft has created.

C# is a great little language. With stonger typing and faster execution than VB, it’s C/Java style syntax is a lot cleaner and less verbose. I have moved all my new projects to C# and thus far have had excellent results. If you can write Java or C/C++, and you know OOP, you will have no problem learning C#.

Finally, the .NET class libraries. The .NET lib is huge and has basically everything. The ASP.NET classes contain a vast amount of utility controls, and functionality like HTTP servers, I/O filters, logdaemons, and other such niceties for a server dev.

Now, on to the knocks. Hey, it wouldn’t be a Microsoft product without some serious flaws, right?

First up is Visual Studio.NET 2003. For 900 bucks I expect the HTML editor to work. Unfortunately, it sucks. They used the Frontpage HTML gen libraries! Remove the WYSIWYG form tools, and the big giant productivity gains go right out the window.

Next up, many of the supplied ASP.NET controls, especially the Datagrid, suck. There are numerous gaps in their functionality which essentially defeat their usefulness. Example – you cannot set a querystring with multiple parameters without resorting to mingling program code in template.

Finally, despite all the talk about ‘Managed Code’, many, many of the .NET classes are just wrappers around existing, sucky COM objects. Imagine my joy when I discovered that System.Web.Mail was really just good ol’ POS CDONTS in disguise.

In conclusion:
ASP.NET is an excellent package, and goes a long way towards redeeming Microsoft as a developer tools company. Yes, there are flaws, but the overwhelming sophistication of this toolkit is quite impressive. While it does compare favorably with other tools, it suffers from some key flaws, and a lack of platform portability. As always, your mileage may vary.

If you are a pro web dev, I would advise getting some familiarity with this toolkit – it’s going to be around for a while.

C has no string type


#include <stdio.h>
#include <string.h>
#include <stdlib.h>

const char *s1 = "ZBCDEF";
const char *s2 = "ABCDEFG";

/* strlen using compact pointer notation
*/
size_t MyStrlen(const char *s1)
{
    const char *ptr = 0;                        
    
    while(*s1)                                    
    {
        *s1++;                                    
        ++ptr;                                    
    }        
                
    return( (size_t)ptr );                     
}

/* String comparison using compact pointer notation
*/
int MyStrcmp(const char *s1, const char *s2)
{    
    while(*s1)                                     
    {
        if (*s1 == *s2)                         
        {
            *s2++;        
            *s1++;
                                                
            if (*s2 == 0 && *s1 == 0)         
                return(0);
            else if (*s2 == 0 && !*s1 == 0)     
                return(1);    
            else if (!*s2 == 0 && *s1 == 0)     
                return(-1);            
        }
        else if(*s1 > *s2)                        
        {
            return(1);
        }
        else if(*s2 > *s1)                        
        {
            return(-1);
        }        
    }
return(0);
}

char *GetSubString(const char source[], int start, int count, char result[])
{
    
    if ((unsigned int)start > strlen(source))         
    {                             
        *result = 0;                                
    }
    else
    {    
    
        if ( (unsigned int)start + count > strlen(source)) count = strlen(source) - start;

        while(start > 0)                        
        {
            source++;
            start--;                                
        }

        *(result + count) = 0;                        
    
        while ( count > 0 || *(source + count) != 0 )         
        {
             count--;             
            *(result + count) = *(source + count);    
        }
    }
    return(result);
}

#define RESULT_MAX 19

int main(void)
{
    char result[19];
    const char source[] = "JIBSON GLOMGOLDS";
        
    printf("nMyStrlen: %inn",(int)MyStrlen(s1));
    printf("MyStrcmp: %inn", MyStrcmp(s1,s2));    
    printf("GetSubString %snn", GetSubString(source,1,5,result));

    return(0);
}


Fun with pointers, see if you can figure it out. By the time I finished this, I finally understood pointers.

C is a great language, try it today.

VS.NET – STOP REFORMATTING MY HTML

Visual Studio reformats your HTML as it pleases when switching from design to HTML mode – a massive bug!.

(c) Mike Moore/Microsoft.
I found that the development team did seriously consider this bug. The first thought was to add an option to turn off the reformatting feature. Unfortunately, it turned out to be deeply integrated in the code that makes the editor useful. So, it could not be turned off. Nor could it easily be fixed. Any changes made to this area of the code would definitely impact many aspects of the editor.

Note to Microsoft’s VS.NET group – you blew it! Fix the bug, fix it before Whidbey!

Read More…