Back on the backend - oh joy oh joy!!!

smalpierre

New member
I am SOOOO glad to be getting back to the actual workie bits instead of the fluffy stuff ...

Expanding an old user authentication system to include contact data - they only want newsletters off the bat, but I try to keep it future resistant, and able to easily add capture for other data. They don't even need user auth yet, but it's better to tie newsletter automation into that than build a separate hack that would end up having to be merged later anyway.

Next on the agenda - I'm building a front controller. I've been using Slim for a front controller, but as light as it is - it's still heavy for my taste, and I hate having to hard code routes. This one is going to be extremely light - it'll pull routes out of the database kind of like WordPress - except Slim like in that I can set variable fields - like this:

/articles/categories/:categoryid

where the colon before categoryid denotes it as a variable like a querystring.

Or /articles/:year/:month might get you all articles within the year and month you pass it in the URL

Slim has a bunch of stuff I never use. Might as well get rid of another dependency. I'll still keep all my application and templates outside the webservers directory too. The only thing web accessible will be an index file that includes the front controller, and any resources like images, css, javascript - things you could get regardless.

Then my dependencies on the backend will be PHP, and MySql - not a single third party library :)


When I get it to a useable state, I'll release the Kraken into the wild ;) No admin tools yet, so if you want to use it get used to using Workbench haha! The table structure is pretty optimized considering, so it'll be pretty easy for anybody to figure out.

After the front controller comes a db prep tool, then admin tools, then a forum system, then a blog system me thinks. Might do an ecommerce system before blog, who knows ...

I'll be releasing it to yous guys first if y'all want to try it out and let me know where it needs improvement.

I'm also going to be porting it to a compiled version - either Delphi (Well, Lazarus, a delphi clone) or C++. Not sure if it'll be CGI or ISAPI yet (need research - tbd). I'd LIKE to do it as a CGI, but the whole reason I'm doing that is to get a persistent database connection - no reconnecting to the database every single time a page request comes through.
 

smalpierre

New member
Update - insert profanity here!

I've discovered that I have validation code in the controllers that should be in the model. one more thing to be fix'd for later.

Some of it belongs in the controllers - things that don't get stored. Things like contact forms that only shoot out an email? Yeah validate that in the controller. Anything and everything that gets stored in the database? validate that in the model.

So now I've got to come up with a better error messaging system. That's going to come after the front controller, and before feature upgrades. Well it should, but I could always move forward. Maybe I build the new features alongside the error messaging then backport to the older stuff before admin tools ...

Insert more profanity here.

At least I'm doing all this while I'm still working in a scripting language right?
 

Genesis

Administrator
Staff member
You've got to be working at 120 miles per hour. That is an ENORMOUS project! :drinks:
 

smalpierre

New member
it's a full time job for sure. I was up til 3am last night hacking away! Back at it for a while today if I can get these dang dogs to shut up - there's 8 of them here, a constant barkfest haha!


Another thing I'm trying to get rid of is jQuery. I HATE jQuery. Well maybe not hate, but I don't like the syntax, and I don't know it all that well - not to mention being a little heavy for what I need and it's yet another third party dependency ...

The only problem is that the menu I'm using uses it, and so do a lot of others. I'm going to be modifying it to use the checkbox hack instead of jQuery to toggle. I think the last one i did used one small bit of javascript to make it work well in some cases - not sure but I think it had to do with iOS. Maybe it's because I set the checkbox to display: none instead of hiding it with absolute positioning.

That's for another day when I get back on the front end though. Right now I'm in backend heaven :)
 

Genesis

Administrator
Staff member
smalpierre said:
Another thing I'm trying to get rid of is jQuery. I HATE jQuery. Well maybe not hate, but I don't like the syntax, and I don't know it all that well - not to mention being a little heavy for what I need and it's yet another third party dependency ...

The only problem is that the menu I'm using uses it, and so do a lot of others. I'm going to be modifying it to use the checkbox hack instead of jQuery to toggle. I think the last one i did used one small bit of javascript to make it work well in some cases - not sure but I think it had to do with iOS. Maybe it's because I set the checkbox to display: none instead of hiding it with absolute positioning.

That's for another day when I get back on the front end though. Right now I'm in backend heaven :)
Aha. jQuery. I came across it a week ago with investigating a responsive navigation menu - tinynav.js that uses minimum JS. Tinynav.js is the older and lighter version of Responsive Nav. Have you come across either of the two?

I couldn't get it to work with my old Website though. It worked but looked everything but the way it should. I've ditched the idea of making something responsive unless its design leans itself to a clean upgrade. Am now at redesigning from scratch.
 

smalpierre

New member
I've been using ajax since 08 or so, a couple of years since it came out. Not heavy, just use it for what I need - and jQuery since 09, 10 something like that - but it SUCKS ... lots of people like it, and there's a huge amount of examples. It's hard to find an example in javascript these days that's NOT jQuery ...

If you're going to stay the path away from jQuery, It's a double edged sword. For me, I'm used to C/C++, Object Pascal, PHP - and other C style languages. Technically jQuery complies - it uses chained closures to achieve it's crazy looking syntax - but I might as well be reading japanese sometimes.

The benefit is that most all Javascript examples will be for jQuerys syntax. If I had to pick ONE library to start web development over the past few years it'd be jQuery.

When the big javascript library war was going on (we all know who won early on ...) I tried jQuery because they were pulling ahead fast, Dojo - because their paradigm was right, and ExtJS because .. well because they have the right idea. Ext has it's own issues though - 1, it's mostly UI code. 2, there is a license vagueness between proprietary / open source versions, and 3 - it's not widely accepted and used.

You want to be proficient at things that are widely used in your field. You want to focus your time learning things that make your job faster, easier, and more efficient. YOU probably want to learn jQuery - but keep in mind, it's just a library. If you're learning jQuery at least expose yourself to some vanilla javascript. I'ts been around since the 90's - it's not going away, especially since everybody loves jQuery which happens to be a JavaScript library.

Keep in mind though, that at some point - probably sooner than later, something else will take over and it might not use the anonymous function chaining like jQuery does. It'll probably be more like standard object oriented / procedural code like is common in most other languages including JavaScript.

What do you want to do with it is an important question. Don't jump on solutions with no problem. jQuery is used a lot for ajax, and because window.onload sucks - so it makes something like it that doesn't suck.

Can we format code in these forums? I'll try:

Code:
// Probably should move this to an includes file
var HttpCodes = {
    OK: 200,
    FileNotFound: 404
}

function domReady(f) {
    // if DOM loaded, execute immediately
    if (domReady.done) {
        return f();
    }

    // if function has already been added
    if (domReady.timer) {
        // add to list of functions
        domReady.ready.push(f);
    } else {
        // attach event - use addEvent in case it finishes first
        addEvent(window, "load", isDOMReady);

        // initialize array of functions to execute
        domReady.ready = [f];

        // check to see if DOM ready as quickly as possible
        domReady.timer = setInterval(isDOMReady, 13);
    }
}

function isDOMReady() {
    // if ready ignore
    if (domReady.done) {
        return false;
    }

    // check if functions and elements are accessible
    if (document && document.getElementsByTagName && document.getElementById && document.body) {
        // if ready, stop checking
        clearInterval(domReady.timer);
        domReady.timer = null;

        // execute functions that are waiting
        for (var i = 0; i < domReady.ready.length; i++) {
            domReady.ready[i]();
        }

        // clean up
        domReady.ready = null;
        domready.done = true;
    }
}

function xhrGet(url, callback) {
    var xhr = new XMLHttpRequest();

    xhr.open('GET', url, true);

    xhr.onreadystatechange = function () {
        //if (xhr.readyState === 4 && xhr.status === 200) {
        if (xhr.readyState === xhr.DONE && xhr.status === HttpCodes.OK) {
            callback(xhr);
        }
    }
    xmlDoc.send();
}

function xhrPost(url, data, callback) {
    var xhr = new XMLHttpRequest();

    xhr.open('POST', url, true);
    xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

    xhr.onreadystatechange = function () {
        //if (xhr.readyState === 4 && xhr.status === 200) {
        if (xhr.readyState === xhr.DONE && xhr.status === HttpCodes.OK) {
            callback(xhr);
        }
    }
    xhr.send(data);
}

That's the library I use for most ajax, and to add multiple functions to body.onload. No need for jQuery to do that.


It's not going to give you javascript UI elements, but I don't think that's a good use for javascript. Might have to use it for accordions, and yada yada - but do you really need them? Are they really what makes a great UI? I personally try to keep JavaScript out of that as much as possible - maybe it has to do with coding back in the days where JavaScript animations and shiny 90's / early 2000's bling tortured the hell out of every website out there? Well except for Google ... see where I'm going with that?

Do you need a flashing banner that follows the mouse cursor like an airplane towing a banner - with each letter spinning on it's axis in 3d chrome? Heck no! It's bling, and detracts from a stable useable user experience. Look back on that thread about horrible websites - and you'll see terrible layouts, a TON of animated .gif images, and a lot of - javascript UI elements like animations that are a huge attraction of jQuery.

That being said - I still do use jQuery because it does have a place and purpose for now.


A programmer that's never seen javascript before - but has seen C, Java, Pascal, Cobol, RPG - AS/400, Python, or any number of different languages - even SQL ... can read this code and have an idea how it works. That is not the case with jQuery.

That's not to say it isn't useful, or that you should avoid it though.


@Genesis - I've heard of Responsive Nav, but it's not a player. Buzzwords now are Angular, NodeJS (server side), jQuery - at least in the Javascript world.

I haven't used AngularJS, but it's a google product, and it's been building steam. Lots more people now are looking at vanilla javascript than they were 3 years ago, so maybe jQuery is finally on it's way out. It's not gone yet though.

One thing jQuery has over Angular - Comet. It's like Ajax in reverse - server push data. I haven't had a need for it but it's been around since at least '10. I think it relies on server polling though - so it's not REALLY server pushed. Who cares though, blackberry RIM used server polling for it's "push" email service - it doesn't matter how it's really done, it matters how the user perceives it.
 

Genesis

Administrator
Staff member
I'm not a great fan of Javascript on the receiving end. Probably should learn more about it though. It does have the ability to create awesome menu bars.
 

smalpierre

New member
I use it pretty much to make ajax calls. Ajax is great for keeping things non-blocking, and things like logins where you don't necessarily want the user to leave the current page just to hit a login script, or switching out menus and options.

Login/register is a good example. When you aren't logged in, it shows login/register menu - when you log in it can change to a welcome *user* / logout gimmick.