Archive for category Coding

The experiment goes on

In my previous post I started a project/experiment to create a simple Java Rest client. I immediately found that I would need a simple service that didn’t do much in order to test it properly. So that is leading to another part of the project, the simple PHP service. I started writing what I thought would be a pretty simple generic PHP service, then it hit me…I suck at PHP. No really, I haven’t done it in a while, and even then I wasn’t highly proficient. So I scrapped the whole idea and decided that someone out there in the interweb must have created a simple PHP rest service thinger. As it turns out, I was right

This project was super simple and did everything I needed it to do. Predefined service routes and responses. Yes, I could shoe-horn it into doing a lot more, but I don’t need that. Just something easy to create and modify service responses to test my simple client with.

I guess after all this I have to say that the old mantra of Unix coding is really starting to die out. “Make each program do one thing well” It seems everyone is so concerned with creating programs that do everything for everyone, they don’t do anything very well.

, , , ,

No Comments

Simple Java Rest Client

I added a new page for my newest experiment. I had to create a very simple REST client for a project that couldn’t depend on any outside libraries, just the standard Java EE libs. I got it build and functioning, but it’s pretty barebones right now. It was a good learning experience and I plan to continue that, making it more functional and complete. The goals of the experiment are:
1. It will be a single java file
2. It will not depend on anything other than the standard Java libraries
3. It will handle HTTP and HTTPS
4. It will handle all standard HTML responses in a logical fashion (thats open to interpretation right now)
5. It won’t suck…

Well thats all I have right now. Check the project out here if you want.

, ,

No Comments

These are not the same

I have been coding for over a decade now and one thing about other coders has never ceased to annoy me. In defense of my rant, I present two snippets of HTML code, see if you can pick out the difference and the source of my exasperation, I’ll leave it up to you to make the determination as to which is the good and which is bad:

<div id="content">
    <div id="content-wrapper">
        <h1 class="layout-indent">Page Title</h1>
 
        <div class="separator thick-separator">
            <div class="thick-separator-cap thick-separator-left-cap">
                &nbsp;
            </div>
 
            <div class="thick-separator-cap thick-separator-right-cap">
                &nbsp;
            </div>
        </div>
 
        <div class="layout-indent">
            <div class="yui3-g">
                <div class="yui3-u-1-3">
                    <a href="#" class="link action-link ">Filler Text....<br />
			<img class="link-arrow" src="img.png" alt="" />
		    </a>
                    <div class="clear">
                        &nbsp;
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<div id="content"><div id="content-wrapper">
<h1 class="layout-indent">Page Title</h1>
<div class="separator thick-separator">
<div class="thick-separator-cap thick-separator-left-cap">
&nbsp;</div>
<div class="thick-separator-cap thick-separator-right-cap">
&nbsp;</div></div><div class="layout-indent">
<div class="yui3-g"><div class="yui3-u-1-3">
<a href="#" class="link action-link ">Filler Text....
<br /><img class="link-arrow" 
src="img.png" alt="" /></a>
<div class="clear">&nbsp;
</div></div></div></div></div></div>

The structure of these snippets is identical, they probably layout the same between browsers too. I guarantee you that if anyone ever had to make a change, the first one would be far and away easier to change. So why do people still insist on editing spaghetti code? This isn’t just an HTML issue, it happens in every coding language I have ever encountered. I just want to say to people, “Would it kill you to use the tab and enter key from time to time?”, its as if not indenting their code will somehow make them work faster. “Look boss, I saved 2.78 seconds last week, by not formatting my code!!” In my opinion it really shows that someone [programmer] has pride in their work if they spend the extra few minutes documenting and formatting their code.

,

No Comments

Hobby programming projects..

I started a project about a year ago, I started to make a game. I have only ever developed web based applications, so the idea of having a loop that just, well keeps looping has been difficult to wrap my head around. I had grand ideas, of how it would play and what it would look like. I started coding like a man possessed. I bought a book and almost finished it. Then, my enthusiasm started to wain. I wasn’t making the progress I was in the beginning, I wanted to head in a direction that the book wasn’t going. So I started to wing it…Then I realized how much I really was leaning on the examples from the book. i got frustrated and took a month off, and when I came back to it, none of it seemed to make any sense.

I got the project all setup in SourceForge and I was checking things in and out of SVN there as I worked, but I felt like I was swimming upstream. I never seemed to make any progress. So tonight as I stared at my editor with some of the base classes open in front of me. I thought, should I just give up all together? What ever happened to those dreams of making this the coolest open source game out there? Its seems sad that for all my excitement at the beginning, it takes herculean effort to just open my editor at home and sift through all my old work.

So is this where its going to end…?

No Comments

jQuery vs Prototype

I have been using the Prototype Javascript library for my client side needs as of late. It works reasonable well and there are a number of shorthand operators that simplify (albeit obfuscate) my code a bit. The thing I find disheartening is that alot of JS programmers discredit Prototype for its lack of documentation and extending of of the native data types (String, Array, Object).

I haven’t run into a single case in my experience where the extending of the native types has caused any problems. The thing that does cause me concern is the fact that Prototype is 71K uncompressed. I have tried packing it, but it just mangles the code. Then I tried Alex Russel’s rhino-based packer, it works but it doesn’t compress near as well as Dean’s. So I am still left with a 48K JS file.

jQuery on the other hand does compress with Dean Edwards packer and it packs nicely (53K down to 19K). But it is a massive paradigm shift in the way the library approaches Javascript. Where Prototype extends native types and creates its own with some shortcuts to save code, jQuery wraps everything in its own custom jQuery object then works on that. I haven’t had enough experience with jQuery to comment intelligently on it but I am hesitant to learn a library where it essentially discards the native types and does its own thing. You hand it either a DOM object, or JS object and it hands you back what it thinks you want based on how you manipulate the jQuery object after its be instantiated. Maybe I am looking at it too simplistically, but that is what I have seen thus far and I haven’t been liking it much.

Oh, and everyone complains that there isn’t any documentation for Prototype? Sergio Pereira keeps the documentation up-to-date and in multiple languages here. That has been more than sufficient for me, granted it doesn’t have the slick interface that VisualjQuery.com has.

No Comments

…and why not!?

I am sure I am not the first person to have run into this in my Javascript adventures. The generous individuals that created the Taconite framework probably wrestled with this issue, and I am sure there are others.

But can someone, please, tell me why, I can’t take issue an XMLHttpReqest, get text/xml back, take a snippet from that response and appendChild/replaceChild/etc.

The current solution is to get xml (yes yes RF, a string representation of xml), then loop through all the nodes, grab the tag name, then do a document.createElement. Is it just me or is that just plain inefficient? Lets see here, I have a response string that is magically transformed in a DOM fragment by the XMLHttpRequest, then I have to re-parse that DOM into another DOM, because why again?

Alot of people bellyache about how innerHTML isn’t in any spec, which it isn’t, but then they jump through every hoop imaginable causing a ton of overhead and complication to get around not using it. But even so in order to use innerHTML I have to serialize my text/xml response into a string. So there is more overhead there. I am with others that when someone blames the complier for errors to raise more than the curious eyebrow, but this seems like something is definitely broke.

No Comments

Syntax highlighting

I have been meaning to post alot of the code I use day in and out, so that other could benefit from it. But I didn’t want to just slap some code and have it looking all nasty. I think format and syntax is part of the art of coding. How sexy is monochrome code that is all in Courier and no indenting? Not very.

I tried a number of other syntax highlighters and none of them seemed to work quite right. Then I stumbled here: http://erik.range-it.de/wordpress/plugins/syntaxhighlighter/

It uses the uber-cool dp.SyntaxtHighlighter. Check out my first page where I use it. Good stuff.

No Comments