Jay Taylor | programmer notes

Archive for August 2010

This time it’s the old-spice guy in a form unlike that which I could have ever imagined possible:

Re:cool (Score:5, Funny)

by nacturation (646836) * writes: <nacturation@gmai … m minus language> on Friday August 27, @01:09PM (#33394538) Journal

It’d need some way to determine how your eyes are focused though – whether you are intending to look at your hud or something distant. Hold up an object up to your eye about where your glasses would rest. Close the other eye that won’t see the object. Look at the object, then look at the wall behind it.

Now look back at the object. Sadly, it isn’t your eye. But if it had a fine enough resolution it could be compatible with your eye. Look down, back up. Where are you? You’re on Slashdot looking for the display your display could look like. What’s in your hand? Back at me. I have it, it’s the iPhone 5 with a display so fine you can’t tell the difference. Look again. The iPhone display is now a projector. Anything is possible when your device is made from nanoresonators and not a retina display. I’m modded up.

, Hide

Found myself sort of longing to un-hungarianize some PHP classes.  Here is more information regarding Hungarian Notation.

First off, vim rocks.

Here is the regex to (pretty safely and reliably) de-hungarianify a PHP class:

(Each group is colored for clarity in identifying which section is which in the explanation)

%s/\$[a-z]\([A-Z]\)\([a-zA-Z]\+\)/$\l\1\2/ge | %s/\(private\|protected\|public\|var\)\s\+\(\$_\?\)[a-z]\([A-Z][a-zA-Z]\+\)/\1 \2\l\3/ge | %s/\(\$this->_\?\)[a-z]\([A-Z][a-zA-Z]\+\)\([^(]\)/\1\l\2\3/ge

Explanation:

%s/\$[a-z]\([A-Z]\)\([a-zA-Z]\+\)/$\l\1\2/ge

Does simple variable name transformation of $bSomeFoo into $someFoo. This also removes the hungarian notation from statically referenced variables.

%s/\(private\|protected\|public\|var\)\s\+\(\$_\?\)[a-z]\([A-Z][a-zA-Z]\+\)/\1 \2\l\3/ge

Strips the hungarian notation from class member variable declaractions, e.g. private $_bSomeOtherFoo into private $_someOtherFoo.

%s/\(\$this->_\?\)[a-z]\([A-Z][a-zA-Z]\+\)\([^(]\)/\1\l\2\3/ge

Strips the hungarian notation from class member variable references, e.g. $this->_bSomeOtherFoo into $this->_someOtherFoo.

Keep in mind that this could still break stuff if public class member variables are referenced externally in another file, or if the file you run this on references hungarian-notation in other classes that you haven’t updated.

, , , , , , , Hide

Find it!