All-powerful Java code snippet

26 02 2009

As a joke (but not really), I was terribly annoyed at Java today, and wrote this Java code in a few minutes.  It’s (not surprisingly) capable of accomplishing *anything*.  Give it a shot.

ProjectAttempt project = new Project();
try {
    attempt = project.codeWith(Java);
    if(   attempt.results == tooRigid
          attempt.developmentTime > acceptableThreshold) {
        // since the above condition is usually true,
        // we should expect this next line to happen frequently

        throw ExceptionallyNotGoodEnoughException;
} catch (ExceptionallyNotGoodEnoughException e) {
    System.out.println(" ERROR: Java is too rigid!");
    System.out.println("1 a: deficient in or devoid of " +
        "flexibility <rigid price controls> <a rigid bar of metal> ");
    System.out.println(" b: appearing stiff and unyielding <his face rigid with pain>");
    // Don't bother with another try/catch block,
    // since it's impossible for the next line to fail.

    attempt = project.codeWith(Python);
    // Should always read "Impressive"
    System.out.println("Development time: " + attempt.developmentTime);

Smart-alec replies are welcome, but you won’t change my opinion on the matter 🙂


ThePirateBay speaks by political cartoon

25 02 2009

Whether you support or condem , I don’t think you can refute the message being presented here…


Microsoft lawsuit in EU over packaging IE (again)

25 02 2009

Can someone tell me why we feel the need to harass Microsoft for bundling IE on their own flipping OS?

Without IE, I wouldnt’ be able to get online very easily, to go download Chrome or FF or Opera or whatever.

If MS is forced to remove IE, they should also have to remove every MS-made operating system driver.  By the gods, they are taking away my ability to choose which driver powers my DVD burner!!  To hell with MS and their packaged drivers!

Get real, you idiots.  Let them package their browser.  Apple does.  Ubuntu packages someone ELSE’s browser in their operating system!  If that isn’t deplorable (by the lawsuit’s standards) then I don’t know what is!

Windows 7 – better than sliced bread

24 02 2009

If you’d like to see me give screenshots (at full resolution, instead of the crappy Youtube video quality) or more info of anything else at all, let me know and I’ll post as much as I can about it.

The public Windows 7 beta is build number 7000 (nicely timed, Microsoft).

Honestly, the easiest way to get the beta (as of the time of this writing) is to use an MSDN account.  MS really gives away their software like candy to anybody with an account on MSDN.  You can generate activation keys on the spot, and download whatever software you want.

Especially in light of jokes (such as the one found here) and overly harsh criticisms,  I thought I’d help defend Windows 7.  (Notice that I didn’t say that I was defending Microsoft.)

I run the Windows 7 beta as my primary operating system, currently, so I’m speaking from 100% pure experience.  And your Linux/Unix lovers will need to come to terms with the fact that Windows is getting better and better, not worse and worse.  If you think it runs too slow, then your computer is outdated for personal desktop use on a modern operating system for professional software.  I would like to take this opportunity to shout out to a nameless person whom I met one evening, to let him know that if only Windows had a built-in SSH server and a distribution of gcc or something, it would give Linux a run for its money, in terms of the tech world.  The base kernel has been shrinking in size with each release, and in all reality, it’s getting faster.  If it appears to be slowing down, then it’s because your GPU sucks, and you need a video card.  Instead of running the visuals in Windows on your raw CPU, Vista and Win7 tap into the Graphics Processing Unit to more intelligently dish out the visual work load.  That way, your actual computing doesn’t need to bump shoulders with graphics stuff.

Some of the greatest things about Windows 7 are simply the UI improvements.  People take stabbing gashes at Win7 for simply being Vista in a new skin.  Partly true.  But are you completely daft?  Giving Vista a UI overhaul is great!  Win7 is the way that Vista was meant to be from the very beginning.  MS had some troubles back in the late days of XP, and couldn’t focus on Vista enough.  Therefore, Vista came out kind of gimpy-like; it was XP in a new skin, with only a few improvements.  In fact, a lot of the various menus were just lame rips of the old XP menus.  For instance, if you right click your Vista desktop and choose “Personalize”, just about any of the links you can click from there are just single-tab settings dialogs.

Windows 7 fixes that.  It improves upon so many of the various menus, that you’ll grumble to yourself the next time you have to use XP’s menus.

Aside from that, the taskbar got a makeover.  The Quicklaunch toolbar has been sacrificed in favor of the new taskbar.  Those familiar with XP’s “Pin to start menu” option will quickly catch on, since you now have a “Pin to taskbar” option to accompany it.  Basically, your icons get pinned to the taskbar so that they act like the old Quicklaunch toolbar.  However, when you click on the icon, it will become “active”, and the ‘quicklaunch’-ish icon then becomes the active window on the taskbar.

You can do drag-and-drop reordering on the taskbar.

The taskbar items are kinda slick now, as they glow according to the most outlying color in the icon.  Don’t think that this is too much of a waste of system graphics time– MS had been going the route of ‘vector’ graphics, which are calculated in real time, rather than trying to apply bloated bitmaps to everything.  It seems to me that it tries to pick a color on the lighter half of the color spectrum, so that it does in fact “glow” and not “emit dark shades”.  It might seem trivial, but it’s really nice for us visual folks.  It’s great to be able to quickly associate a color with your open programs.

On a similar note, any tasks which take a progress bar will actually display the progress underneath the text of the taskbar item.  Kind of hard to visualize without a graphic:


I threw open a few extra windows for you to see.  Notice that Photoshop is in the middle of the other icons because it is normally “pinned” to the taskbar, but I have it running, so it’s expanded.  Also, it  knows that my instance of Chrome and Gmail are both running from the same executable, so it links them together, and lets the glowly highlight spill into the Gmail item.  The glow changes to red on the Gmail item because the icon’s color is different than the normal Chrome item.  My mouse was sitting at about 2/3 of the length of my Chrome item.

Hidden system tray items pop *up* into a little tray window, so that they don’t have to worry about animating into some goofy sliding motion that crunches your taskbar items.

My wireless signal is represented by an actual signal icon in the system tray, instead of a useless “you have a connection, but i won’t tell you how good it is” icon.

FINALLY (holy heavens) the clock in the system tray tells you what the date is, as well.

That little vertical rectangle at the far right side of the taskbar is a magical “show me the desktop” button.  if you click it, your windows will minimize.  If you just hover over it though, all your windows will go transparent, leaving only outlines, so that you can see down to the desktop if you want, without actually minimizing everything.  This is nice if you have desktop widgets running down there.  (The Sidebar is gone, as it is now just a bunch of free-floating widgets.)  This eliminates the need to make your widgets “always on top” if you don’t really want them to be.  As soon as your mouse moves away from the hovering-enforced hot-spot, your windows come back into full opacity.

Similarly, if you hover your mouse over a window preview on the taskbar, all other windows will fade into the same Aero-esque outlines, while the window whose preview you’re hovering over will stay at full opacity.  Nice for a developer like me, when I’ve got several windows open from the same program.  I quickly lose track of which window is which, so visual feedback like that is wonderful.

And check out this “removable device” popup when you click on the icon in the taskbar:

removablemediaI’ve got one of those 12-in-1 memory card drives, so it was pretty useless in Vista or XP when I clickedon that icon, because it would only tell you random drive letters and the like.  Now, it tries to split it up by the physical hardware.  I intentionally put in my camera and iPod, so that you can see what kind of effect they were shooting for this time around.  That main “F:\” section on the bottom is my 12-in-1 card reader, which has 5 slots in it.  Only one currently has a card in it, so it naturally shows the card’s  name.

On a related note, Windows Explorer now hides (by default, changeable via options) your empty drives, so that if there’s nothing in it, you won’t be overwhelmed by an onslaught of drive letters, where you have to guess-and-check to discover which one your card is in.  I think  your CD/DVD drive stays there at all times though… not sure.  Actually, I checked last night, and it does hide CD/DVD drives, though if you simply click on “My computer”, it’ll show you all your drives, whether they have media in them or not.

The other major thing that “matters” is this new thing called your Libraries.  A Library is basically a folder that aggregates files from other ‘source’ folders.  For instance, I have a backup external harddrive, and so my Pictures Library aggregates from “My Pictures” (from my User folder), “Public Pictures”, and then my backup drive’s “Picture” folder.  Pretty sweet.  They’re trying to have the Libraries replace your User folder’s “Documents”, “Pictures”, etc… You still have access to your personal folder, but by using the Libraries, you don’t have to worry about digging around to see Public documents, images, or videos… they’re just right there in one spot, even though they exist in separate spots.

I won’t bore you with the other little details, but let it be known that Win7 is a big step forward.  It seems to take up 150-250mb less RAM when turned on and sitting idle in it’s “ready” state after startup.  Even while I was running a remote desktop session last night, along with Hamachi, the basic iPod services, and a few other nickknacks, the OS was running at 632mb of RAM usage.  Compare that to my work machine with Vista Business on it, which instantly takes up about 865-900 after startup.

And finally, a FANTABULOUS selling point is that it’s written on the same Vista code-base, so programs are generally compatible with Windows 7 right out of the box.  Photoshop warned me that it couldn’t verify that I was running Vista SP1, but allowed me to install anyway.  My motherboard driver refused to install because it was coded by a bunch of lame idiot programmers who detected my OS’s name, rather than my OS’s actual capabilities.  Let that be a note for programmers everywhere: code with your platform’s/object’s abilities in mind, not it’s actual type.

And that’s that.  I may post more in the future.

Fastest friggin emailer in the West

24 02 2009

I, just so you know, managed to send an email before it could be sent.  Doesn’t make sense?  Check out this screen-shot I snagged in gmail just before it switched to ‘0’


Now, I’m a decent photo editor, but I swear it was real 😛  In fact, just a few seconds after I took the screenshot, it corrected itself to a non-negative integer, haha…

Don’t mess with my blazing fast speeds, for I am a hero.  A friggin super hero.

Dear Loyal Java Fan,

20 02 2009

Why is it that, to you, “Object Oriented” is a synonymous colloquial abbreviation for Absolutely everything must be inside of an Object, even if it kills me, so help me God” ?

Callbacks.  Yes, I’m perfectly aware that Java can implement callback routines (via an implementation of a prototype Interface, or Observer, or whathaveyou), but are *YOU* perfectly aware that a simple callback function/method sometimes doesn’t need all the verbose scaffolding that Java makes you jump through?

In fact, the very reason why a “callback function” was designed as it was, had to do with the fact that it was a single “function” (or “method”, if you prefer).  It was not a “callback object”.  There’s a good reason for that.

You’ll probably argue that I’m just accustomed to the C-style callbacks, and that Java’s are just as well.  And yes, this is me insulting Java.  Java is not perfect.  Accept that fact.  Java’s style is cumbersome.

Because Java’s OO framework only really support pointers to objects, you’re actually incapable of passing a function/method reference as a callback function, for the host method to execute arbitrarily.

The task is simple: call a routine, pass a function which defines behaviors.  Frankly, there’s no reason for there to be a whole object enveloping this function.  After all, it’s just a function.  Its only purpose is to define some routine.

It feels like Java is rather OO “trigger happy”.  And because of this, setting up a quick callback method (to pass into another method to execute) becomes a friggin beast of a task.  This guy describes a 3-step process for accomplishing the task.  One part is an interface, another implements that interface and solidly defines some methods, and then there’s the executing class, which takes in an ‘implemented’ interface and can run a particular method from the object created in step 2.

That’s all well can good, but… all I want to do is pass an arbitrary callback to be invoked later on.  I don’t want to create an interface, implement it, and then write an invoker class (which, by the way, only invokes some hard-coded method from the object it is given).  The only way to simplify it is to try to abbreviate with an anonymous inner class on your implemented interface.  Sure, it’s more “inline”, but it’s still way more time consuming than a simple function reference.

Consider this thread, where the thread starter fears the very reality that I am also annoyed with: “don’t know how in Java (other than possibly wrapping up the function in an object ? – good grief please say it isn’t so !

And then the typical Java junkie reply comes in the very next comment: “If you fear objects, you shouldn’t program in Java.” and then later “What, you’re averse to using objects in an object-oriented language?”  Quit being so dense, you idiots.  He doesn’t fear the objects themselves.  Instead, he (and I) fear the fact that every aspect of Java annoyingly forces you to make an object out of something that should be far simpler.

(And then props to the guy who said “you post some example code of how ‘you’ would implement the Observer Pattern in C++.” … psst.. who’s he quoting when he put the single quotes around ‘you’?  You don’t place emphasis with quotes, man.)

The point at hand is that a language can be object oriented without being disgustingly anal about wrapping everything up into class definitions.  It is for this very reason that coding in Java slows you down.  Dear God, just pass a function reference and be done with it.  And it’s more flexible, too.

Don’t complain that passing function references makes the code harder to debug.  I personally find well-documented code to be *far* more valuable than needlessly stupid class objects littering my project.

Modern Programming: Leaving Java – Part 2

16 02 2009

So, part 1 was all about our current circumstance in the world, with Java being a bit “dusty” (to use the term I used in the part 1 post) when held in comparison to the ideas backing new languages.

To recap the most important idea from part 1:  Java was a great step forward for its time, but there is of course the possibility of a better idea than Java.

Was the original brick cell phone the end-all solution for cell phones?  Heck no.  Was Compaq’s first laptop the best design, just because it was the first of its kind?  Absolutely not.

Just so, C and Java are not necessarily the best end-all solution, no matter how good you feel either of those languages is.

As I pointed out in part 1, there is a good legitimate use for (almost) every language, regardless of anything I say against any language.  Thus, Java will never *actually* disappear, just like C will never actually disappear.  I’m okay with that, but I wish to bring a better understanding to those of you who code in Java who would like to crucify people like me for suggesting that Java isn’t the best solution.

Part 2: Something of a Design Flaw

We all hate that diabolical moment when the sudden realization hits us: there’s a design flaw, and a project redesign is needed in order to accomplish the necessary task.  And it’s either a redesign, or you’ll be forced into more countless hours of trying to code your way around the design flaw, thus the code becomes convoluted, and making it impossible for the next guy to easily grasp what’s going on.

Part 1 was clean of any significant reference to other languages.  Part 2 is not.  You’ve been warned.  I’ve established the foundation of my case in Part 1, and so from this point of view, read the rest of Part 2  in conceptual terms.

If I get any replies on how to better code a Java example, then those persons have entirely and utterly missed the point of what is being presented (again).  If you are one of those persons, then I cry for you and your blindness to outside ideas.

Java’s core development effectively stopped the day the JVM was completed;  “That’s it, that’s all” (as the french Québecois say.. in english).  Once the JVM was made, the Java platform allowed for pretty much any package to be developed.  The JVM has all of its nasty internals tucked out of sight, and coders are free to make whatever code they want, and it’ll run on top of the JVM.  Yes, the JVM is probably tweaked frequently, but huge additions aren’t really in Java’s script (‘script’ as in playwrite).  Therefore, you have to “code around” the design in order to accomplish modern operations on Java’s data types.

This is generally the pattern of most languages: initial core development exits stage right, package development takes the spotlight.  So this being the case, we can’t really expect any overhaul to the JVM and how it works.  Therefore, I present to you concepts.

Programming is becoming more and more “object-oriented”, and rightfully so.  The goal therefore, is to make the code modular.  The goal of modular code is easy deployment/use all over the project’s code.  You change something in one main source file, and the changes are reflected everywhere.

Java (like a few other languages) has saturated (super-saturated?) itself with packages which define hundreds of specialized data structures for certain tasks.  This is great if you understand the fine nuances between their uses.  But frankly, naming two Classes “HashMap” and “HashTable” doesn’t clear anything up for me.  What’s the difference?  (Readers, don’t answer; it’s rhetorical.)

Python’s idea is a bit different: of course it provides certain data structures for you to use, but it decided to circumvent some of this madness.

So here’s the bottom line:  Java says “Pick your card”.  Python says “Write you own card”.

That’s probably a terrifying thought for you Java peoples.  “What?  No Hash generalization to plug into a [Concurrent]Map/Table/AttributeSet/Set ???!!?” And the same applies to Tree stuctures and the whole gang.

No, Python’s job is not to baffle you with finely-tuned data structures that you’ll never master.  Instead, Python’s “Write your own card” approach is used, and it’s surprisingly simple:  You’re going to write what you need to use, but we’re going to make it easy to do that.

Let’s start with something *extremely* simple.  My argument has more weight than this, but you’ll begin to understand soon.  Java did away with simple integer values casting into booleans for use in IF constructs.  Reasoning probably had to do with ambiguity between a ‘1’ and a ‘true’.  To avoid this, Java doesn’t cast ints into booleans.  Fair enough.  But then we explore the rest of how Java compares values.  To test the “value” of an variable, we’re used to using the ‘==’ sign.  The problem with dynamic object is that everything is pointers.  This means that if you ask if Object1 == Object2, you’re comparing their memory addresses which each pointers points toward.  That’s not what you want.  So by necessity, Java provides dozens of methods on each object’s base class called ‘equals’.  And so Java typically tests value by the ‘.equals()’ method.  This sort of removes the ‘==’ from its most common use!  ‘==’ is left only for FOR constructs and simple primitive tests.

Python, and a few other more forward-thinking languages, have added a reserved word called ‘is’.  This solves the issue noted above.  When you want to compare the ‘value’ of two objects, you use ‘==’, but when you want to test the ‘identity’ of two objects, you use the word ‘is’.

The point here is that if you say Object1==Object2, you’re comparing values (the most common case, you might argue), but when you want to ask if Object1 literally IS Object2 (ie, their pointers are the same), Python just makes you compare as Object1 is Object2.

Example follows. Note that in Python, examples are provided with “>>>” prefixing lines that you would type in an interactive console session. Lines without the “>>>” are things returned to you by the Python Interpreter.
# Python
>>> myInt = 1
>>> myBoolean = True
>>> print myInt == myBoolean
>>> print myInt is True

Very simply, the ‘==’ operator is used to ask the integer and boolean values if they “boil down” to the same thing. This is True. But if you ask the integer if it IS the boolean value True, then it returns False, because an integer simple ‘is’ not a boolean.

This is the kind of new stuff that Python (and other languages) are offering to the world. Java is sort of half stuck in this world of mixing the meaning of the ‘==’. If used with primitives, you test by value. If you test with any object at all, you test by memory address, and are thus forced to use Object1.equals(Object2) to test value.

Integrating custom objects in Python into standard Python syntax is amazingly easy.  By contrast, Java rather frequently forces you into writing goofy class methods to perform your tests.

Consider this example of array indexing.  The following seems natural:
// Java
String[] myArray = new String[]{"1", "2", "3"};
String myVar = myArray[0]

But if you write your own object, you can’t ever use indexing notation, to get or set items as the indexed position.  You have to use custom class methods instead.  But in Python, you can integrate with the language by defining methods on your object.  Thus, I can actually tell Python what myCustomObject[0] or even myCustomObject[“sectionName”] means:
# Python
>>> myCustomObject["mainSection"] = "hello world"
>>> print myCustomObject["mainSection"]
'hello world'

In effect, you can have your custom object manage the values however you want; that is up to you.  It abstracts the implementation so that if it ever changes, code other people have written won’t deprecate so easily, because they access the data via standard Python syntax.



Further, you can actually iterate over a custom object in your own custom way.  You can pick what “iterating over” the object means.  You have complete power. Assuming you had several “positions” in your custom object, example code might look like the following:
# Python
>>> for i in myCustomObject:
...     print i, ":", myCustomObject[i]
'mainSection' : 'hello world'
'another' : 'foobars are healthy'

Can you see the power in this?  You have the amazing ability to tell the language how to integrate very simply with the standard language syntax.



Lots of “advanced” object functionality is available to Python’s objects by default.  There’s no need to dig out obscure utility functions to get efficient functionality.  A popular thing about arrays these days are “array slices”.  Simply, this means that you can access several indexes of an array at a time. In Python, your typical idea of an ‘array’ is implemented as a data type called a “list”. This is built into Python automatically. There’s no need to import any goofy package first.
# Python
>>> myList = ["a", "b", "c", "d"]
>>> myList[0]
>>> myList[0:3]
['a', 'b', 'c']
# You can also imply the beginning or end of the list:
>>> myList[:3]
['a', 'b', 'c']
>>> myList[1:]
['b', 'c', 'd']
# Or, you can go backwards:
>>> myList[-1]

See how easy this is?  Say goodbye to excessive myArray[myArray.length – 1] calls.  Lists support pushing, popping, removing specific items, and queries to find out if an element exists in the list:
# Python
>>> myList = ["a", "b", "c", "d"]
>>> myList.append('e')
>>> myList
['a', 'b', 'c', 'd', 'e']
>>> poppedValue = myList.pop()
>>> poppedValue
# Pop from an index:
>>> poppedValue = myList.pop(0)
>>> poppedValue
# Append lists together:
>>> myList.extend(['1', '2', '3'])
>>> myList
['b', 'c', 'd', '1', '2', '3']
>>> "b" in myList
>>> "z" not in myList
# As a side note, you can do the same to any iterable object, including strings or custom objects!
>>> myString = "12345"
>>> myString[2:4]
>>> myCustomObject[1:]
['foobars are healthy']

Much more is possible, but this is good enough to start with.  Just understand how amazing simply Python has made this.  Java is a nightmare compared to this.  It might all seem trivial to you, but Python has decided what the most effective way to perform these operations is simply built in.  Anybody caught using any loops in Python to do these things should be arrested.  Anybody caught using loops in Java to do these things is doing it because they have no choice.



These examples only touch the surface of the differences.  These differences are exactly what makes modern programming languages so powerful.  Yes, there’s a speed trade off, but the productivity to be gained is incredible.  The “scaffolding” of Java and C is overdone.  It is not as needed as it once was.  Python’s clean appearance is easy to read, easy to maintain, and easy to extend.  Python is fully object oriented, and supports multiple class inheritance.  Complex tasks are easier, and you’ll find that you don’t need to code with your browser open to the current JavaDocs.  Python’s just easier.  I’d love to expound on more features of Python which further enhance productivity, so I’ll probably write a Part 3, for those curious to have it explained.

The point is not comparing speeds.  The charts often prove that Java can outrun Python in many tasks.  But as you look at the code to power the Java part of the test, and then compare it to the Python equivalent, you’ll be shocked at how little effort is required to achieve the same behavior.  And with those clock cycles lost in the Python code are more than made up in productivity, allowing you to simply accomplish MORE.  Certain tasks will still require C, regardless of how good Java is.  Nobody seems to complain between the slowness of Java compared to C.  Thus, it’s not a big step to move on to Python.  Modernize.  Get more done.

Until part 3.