Unicode in MFC/C++

To make strings not barf when you switch back and forth between multibyte encoding and unicode encoding….

when defining string literals:
_T(“StringValue”) – works always
L(“StringValue”) – works if unicode rather than multibyte
“StringValue” – works if multibyte

when defining string variables:
LPTSTR myString = new TCHAR[25];

when changing control values:
controlName.SetWindowTextW( myString.c_str() );

This is why I have a love/hate relationship with C++

To make the About This App dialog appear from the System Menu (what comes up when you right click on the icon of the application), considering the About Dialog was already working from the Help menu…

Typical of C++, this requires editing 6 different files, header files, source files, resource files, etc, 98% of which is adding boiler-plate un-original code. There is no reason it needs to be this complicated. On the other hand, a lot of other programming languages don’t even give you that option to add things to the system menu…

Today I implmented SHA-1 in Java

SHA-1 is a secure hash algorithm (called by some the successor to MD5), to be used as some sort of password generator for an application that I understand about as little about as I do the mechanics of how the SHA-1 algorithm works. It does a lot of crazy math and bitwise math to come up with this fixed length magic number.

But I guess none of that’s really important. What it comes down to is that I was given a website with some javascript source code, and they (work) wanted that in Java with some trivial changes to the input/output types.

Converting JavaScript to Java is Ugly with a capital U. Mostly because the more I work with JavaScript the more I’m fully convinced weakly typed languages are inane and obnoxious…especially if you should ever have the misfortune of debugging anything gone awry in such a language. But even though its ugly, it’s kind of fun, I like making things less ugly.

Dates in Java

how to get a non-deprecated time in java:

Date dateFromMessage = new Date(msg.getTimeAsMillis());
String expectedDateString = “1/19/05 2:50 PM”;

DateFormat d1 = DateFormat.getInstance();
d1.setTimeZone(TimeZone.getTimeZone(“America/Los_Angeles”));

String dateFromMessageAsString = d1.format(dateFromMessage);

dtm.publishSubtestResult(
dateFromMessageAsString.equals(expectedDateString),
dateFromMessageAsString + ” == ” + expectedDateString
);

Commenting Out Code

I think I scared myself, when in normal conversation(and by normal, I mean normal for a software engineer), I used the word OBERON. Yep, that’s right [the bane of my existence back in compilers class in college]. And not only did I say it, I was complaining that Java is not more like Oberon.

“If only Java allowed nested comments like oberon…”

Because, as it seems, Java does not appear to have any embedded language features that let you quickly and non-destructively comment out a large block of code which includes /* c style comments */, function headers, and does not necessarily compile where you are teleporting it to. If it were C, I could just add a #if(0) around it. Two short lines, and the entire function is commented out, non-destructively.

The only way I’ve successfully commented out entire functions is the macro and/or search and replace beginning of line technique to slash-slashify every single line. But that’s ugly ugly. ESPECIALLY when the file already contains //ified code, which is NOT my doing…and you can’t tell them apart. So then you start having to do something really ugly like //JRW// as the prefix for each line. Couldn’t I just if-zero it all out of my hair? I don’t want to be spending my time right now figuring out what includes I need, and what to do with these paramaters, and local variables I don’t have here…

or if only you could do nested c-style comments like oberon. (* cuz comments like this (* could be nested and *) that made everything happy, cuz you could comment out code with comments in it…and easily and cleanly… *)