<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Codethink &#187; rant</title>
	<atom:link href="https://codethink.no-ip.org/tags/rant/feed" rel="self" type="application/rss+xml" />
	<link>https://codethink.no-ip.org</link>
	<description>A blog about coding, life, and other arbitrary topics</description>
	<lastBuildDate>Sun, 15 Mar 2026 21:30:15 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.29</generator>
	<item>
		<title>Natural Scrolling Isn&#8217;t</title>
		<link>https://codethink.no-ip.org/archives/736</link>
		<comments>https://codethink.no-ip.org/archives/736#comments</comments>
		<pubDate>Sat, 23 Jul 2011 07:50:05 +0000</pubDate>
		<dc:creator><![CDATA[aroth]]></dc:creator>
				<category><![CDATA[banter]]></category>
		<category><![CDATA[operating systems]]></category>
		<category><![CDATA[lion]]></category>
		<category><![CDATA[rant]]></category>
		<category><![CDATA[scrolling]]></category>

		<guid isPermaLink="false">http://codethink.no-ip.org/wordpress/?p=736</guid>
		<description><![CDATA[Mac users and other developers such as myself who have no choice but to use a Mac for certain projects will already know what I&#8217;m talking about. For everyone else, however, the newest version of OS X includes a most &#8230; <a href="https://codethink.no-ip.org/archives/736">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Mac users and other developers such as myself who have no choice but to use a Mac for certain projects will already know what I&#8217;m talking about.  For everyone else, however, the <a href="http://en.wikipedia.org/wiki/Mac_OS_X_Lion" target="_blank">newest version of OS X</a> includes a most bizarre feature, called &#8220;natural scrolling&#8221;.  Despite its innocuous-sounding name, this feature (which ships enabled by default) breaks the interface to the OS by inverting the direction content scrolls when using the mouse-wheel.  </p>
<p>Apple&#8217;s explanation (and seemingly, justification) for this atrocity of a feature is that &#8220;content should move in the same directions as your finger&#8221;.  Now that&#8217;s all well and good, except for one thing; <em>there is no &#8220;finger&#8221; when using a mouse</em>.  Touch- and mouse-driven are distinct input paradigms.  </p>
<p>Apple is correct in that in a touch-driven system content should indeed track in the same direction as the user&#8217;s finger moves.  If a hypothetical touch-based interface were ever released which scrolled content in the opposite direction of the user&#8217;s finger, then people would say that it was broken.  And rightly so.  Moving content in the same direction as the touch is the intuitive operating mode of a touch interface.</p>
<p>Similarly, moving content in the opposite direction of the scroll (or more accurately, moving the scrollbar in the direction of the scroll) is the intuitive operating mode for a mouse-driven interface.  And it follows that Apple&#8217;s mouse-driven interface in Lion is just as broken as that hypothetical touch-driven interface would be.  By Apple&#8217;s logic scrollbars themselves should also be inverted, tracking from the bottom of the scrollbar to the top as the content scrolls from top to bottom.  Confused yet?  Apple&#8217;s blunder here is that they have conflated mouse-driven input with touch-driven input, without bothering to translate properly between the two.  </p>
<p>As an interesting aside, a comparable analog to touch-style scrolling does exist in the mouse-driven paradigm; the drag operation.  You&#8217;ve probably seen it in things like Adobe PDF documents, and it can also be observed on any scrollbar. In the drag operation you choose an anchor-point, and then that anchor point moves in the same direction that you move, and it all intuitively makes sense. The problem with scrolling using a scroll-wheel is that it has no anchor point from the user&#8217;s point of view (they have done nothing to nominate one, and the UI does nothing to indicate that one has been chosen).  In the mouse-driven paradigm, scrolling is a distinct operation from dragging, and by conflating the two Apple has broken their interface.  At least until they start incorporating a touch-screen into every computer they sell.</p>
<p>If Apple&#8217;s position is to be taken seriously, then we must accept that the current cursor position must always represent where the user&#8217;s &#8220;finger&#8221; is.  There&#8217;s one major problem with that, however.  With a mouse and cursor, the cursor never leaves the screen.  And if the user&#8217;s finger is in constant contact with the screen, then why should there be a separate scroll operation at all?  It would logically follow (since mouse-driven == touch-driven and cursor == finger in Apple&#8217;s world) that since a touch-point exists, and since it is moving, the content (all of it, everywhere) should simply scroll whenever I move the mouse (all the time, everywhere).  But of course that is nonsense, and so is Apple&#8217;s &#8220;natural scrolling&#8221; mouse behavior.  The mouse cursor is not a finger, it does not represent a finger, and its location is not where your finger is touching.  Mouse-driven and touch-driven are different modes of operation, with different intuitive behaviors.</p>
<p>Thankfully, you can <a href="http://www.pcworld.com/businesscenter/article/236182/revert_os_x_lions_page_scrolling_to_the_old_direction.html" target="_blank">turn off &#8220;natural&#8221; scrolling</a> and rid your OS of its nonsense.  I&#8217;ll be happy to turn it back on when my mouse is replaced with a touch-screen display, but until that day comes you can forget about it.  Apple, please stop trying to convince me that moving my mouse cursor around the screen is supposed to be the same thing as dragging my finger all over a touch screen.  It isn&#8217;t, and I&#8217;m not stupid enough to be convinced that it is.</p>
]]></content:encoded>
			<wfw:commentRss>https://codethink.no-ip.org/archives/736/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>[JavaScript] Naming Your Function &#8216;$&#8217; is not Clever</title>
		<link>https://codethink.no-ip.org/archives/720</link>
		<comments>https://codethink.no-ip.org/archives/720#comments</comments>
		<pubDate>Sat, 16 Jul 2011 10:44:26 +0000</pubDate>
		<dc:creator><![CDATA[aroth]]></dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[rant]]></category>

		<guid isPermaLink="false">http://codethink.no-ip.org/wordpress/?p=720</guid>
		<description><![CDATA[The atrocity that is the dollar function dates back at least 2005 and the introduction of the Prototype Framework. Back in those days, &#8216;$()&#8216; was simply a shorthand way of saying &#8216;document.getElementById()&#8216; without having to type all 24 characters. And &#8230; <a href="https://codethink.no-ip.org/archives/720">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>The atrocity that is the dollar function dates back at least 2005 and the introduction of the <a href="http://en.wikipedia.org/wiki/Prototype_JavaScript_Framework" target="_blank">Prototype Framework</a>.  Back in those days, &#8216;<em>$()</em>&#8216; was simply a shorthand way of saying &#8216;<em>document.getElementById()</em>&#8216; without having to type all 24 characters.  And don&#8217;t get me wrong, aliasing &#8216;document.getElementById&#8217; to something shorter is not a bad idea, in and of itself.  But why should &#8216;<em>$()</em>&#8216; be the alias?  Such a name gives no clue that the function is looking up a DOM element by its id.  Something like &#8216;<em>findById()</em>&#8216; (or even &#8216;<em>$findById()</em>&#8216; if there are concerns about naming collissions) would have been infinitely more clear, and still a good deal shorter than writing &#8216;<em>document.getElementById()</em>&#8216;.  </p>
<p>But sadly, Prototype decided to use &#8216;<em>$()</em>&#8216; as the name of their alias.  And even worse, other frameworks have followed in this pattern, adding their own dollar functions that have semantics that can be completely different from the original &#8216;<em>$()</em>&#8216; introduced by Prototype.  Consider <a href="http://en.wikipedia.org/wiki/Jquery" target="_blank">jQuery</a>, which introduces its own version of &#8216;<em>$()</em>&#8216; which can be used to find (and wrap and clone) elements in the DOM by a number of different criteria, but which sadly fails miserably when given a string containing a literal element id.  This creates a lovely situation where now the developer cannot even guess at what &#8216;<em>$()</em>&#8216; is actually doing without first checking to see which framework is being used by the code.  It also means that any code that was written using Prototype&#8217;s &#8216;<em>$()</em>&#8216; will be broken by including jQuery (and vice-versa).  </p>
<p>&#8220;But that&#8217;s what &#8216;<em><a href="http://api.jquery.com/jQuery.noConflict/" target="_blank">jQuery.noConflict()</a></em>&#8216; is for&#8221;, you say.  But you miss the point.  It shouldn&#8217;t be necessary for &#8216;<em>jQuery.noConflict()</em>&#8216; to exist in the first place.  If the jQuery developers hadn&#8217;t decided that it would be cute to define their own version of &#8216;<em>$()</em>&#8216;, then jQuery would never conflict with anything except possibly an older version of jQuery.  The thing that really baffles me is how so many developers (obviously talented developers, at that, considering the work that goes into something like Prototype or jQuery) can all decide that it is a good idea to try to lay claim to a name that exists in the global scope.  Granted JavaScript does not have any concept of a proper namespace, but if jQuery limited itself to only setting properties on an object named &#8220;jQuery&#8221; and Prototype did the same on an object named &#8220;Prototype&#8221; and so on, the current JavaScript landscape would look ever so much more sane.</p>
<p>And of course, this says nothing of the &#8216;<em>$$()</em>&#8216; and &#8216;<em>$F()</em>&#8216; functions that were also introduced by Prototype (and the &#8216;$E()&#8217; and &#8216;$ES()&#8217; functions inexplicibly introduced by <a href="http://solutoire.com/2007/09/20/understanding-mootools-selectors-e-and-es/" target="_blank">MooTools</a>) and whose names are so semantically worthless that a developer has no hope of inferring their function without consulting the reference documentation.  Which again can only be accomplished after checking the entire codebase to determine which framework it is that is defining these functions with its woefully awful naming convention.</p>
<p>If the developers of Prototype, jQuery, Mootools, and the like wanted to turn JavaScript into an unreadable and unmaintainable mess of a language like <a href="http://en.wikipedia.org/wiki/Perl_language_structure" target="_blank">Perl</a>, then I applaud them for their efforts.  But if not then I call them all out on their atrocious naming convention and design decisions.  There is no excuse for this nonsense.  If you&#8217;re building a JavaScript library or framework, then pick a reasonable &#8220;namespace&#8221; to use for it.  This namespace should be the only thing that you bind in the global scope.  Everything else that is part of your library should be bound as a property inside of this namespace.  And there should be no automatic creation of shorthand aliases in the global scope.  </p>
<p>I don&#8217;t think this is too much to ask.  And of course, any developer that wants to use a global shorthand alias can always do:</p>
<pre class="brush: jscript; title: ; notranslate">window.$J = jQuery;
window.$P = Prototype.$;  //or:  window.$P = document.getElementById;</pre>
<p>It takes all of one line of code to set up an alias.  But when you start doing this automatically for everyone that uses your framework you create nothing but problems.  Especially when you jump on the bandwagon and choose the same crappy shorthand alias names that other frameworks are already using.</p>
<p>There is absolutely no reason why multiple JavaScript frameworks should all be competing over the same terrible function names.  This isn&#8217;t a contest to see who can break the most legacy code, or who can come up with the most obtuse API.  <a href="http://en.wikipedia.org/wiki/International_Obfuscated_C_Code_Contest" target="_blank">They do have such contests</a> if you are interested in such a thing, but this is not one of them.  The only thing accomplished by parading the dollar sign around as an example of a well-chosen function name is an increased brittleness in the code that glues together the majority of our modern websites.  It muddies semantics, and creates cases where completely unrelated libraries are not easily compatible with each other, and where simply importing a new library can cause existing code to break.  Even worse, some novice developers get the wrong idea from all those dollar signs flying around think that they need to (or should) prefix all of their function names with &#8220;$&#8221;.  So let&#8217;s put this bad practice to bed before it&#8217;s too late.</p>
<p>So please, can well all stop writing frameworks that give people the impression that calling a function &#8220;$&#8221;, &#8220;$$&#8221;, &#8220;$ES&#8221;, or &#8220;$anything&#8221; is a good idea?  Is it so difficult to choose a reasonable namespace, minimize the number of things that you declare in the global scope, and allow the developer to define a global shorthand alias for this-or-that utility function if they decide they want to?  I think not.</p>
]]></content:encoded>
			<wfw:commentRss>https://codethink.no-ip.org/archives/720/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[C (and variants)] Pointer Declarations:  You&#8217;re Doing it Wrong</title>
		<link>https://codethink.no-ip.org/archives/270</link>
		<comments>https://codethink.no-ip.org/archives/270#comments</comments>
		<pubDate>Thu, 03 Feb 2011 13:51:45 +0000</pubDate>
		<dc:creator><![CDATA[aroth]]></dc:creator>
				<category><![CDATA[c]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[rant]]></category>

		<guid isPermaLink="false">http://codethink.no-ip.org/wordpress/?p=270</guid>
		<description><![CDATA[It happens on occasion, in the programming world, that bad coding conventions become the norm. Consider for instance the following two lines of code: Both lines are equivalent as far as the compiler is concerned, but when a human being &#8230; <a href="https://codethink.no-ip.org/archives/270">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>It happens on occasion, in the programming world, that bad coding conventions become the norm.  Consider for instance the following two lines of code:</p>
<pre class="brush: cpp; title: ; notranslate">int* pointer1;
int *pointer2;</pre>
<p>Both lines are equivalent as far as the compiler is concerned, but when a human being parses these lines intuitively, they say slightly different things.  The first line parses as &#8220;create a variable called &#8216;<em>pointer1</em>&#8216; that is of type &#8216;<em>int*</em>&#8216;&#8221;, while the second line comes across as &#8220;create a variable called &#8216;<em>*pointer2</em>&#8216; that is of type &#8216;<em>int</em>&#8216;&#8221;.  One of these interpretations matches the semantics of the language and what the compiler actually does when it processes this code, and the other does not.  If you are familiar with pointer types, then you know which is which, and if not then I&#8217;ll just tell you that it&#8217;s the first version.  The first line of code is the correct way to declare a pointer.</p>
<p>Sadly, current coding conventions actually favor the second line.  The <a href="http://en.wikipedia.org/wiki/C_variable_types_and_declarations" target="_blank">wikipedia page on this subject</a> even attempts to justify this backwards way of declaring a pointer with the explanation that &#8220;when the program dereferences the pointer, it has the type of the object to which it points&#8221;.  That may hold true in simple cases such as the above example, but now consider the following:</p>
<pre class="brush: cpp; title: ; notranslate">int *functionThatReturnsAPointer();</pre>
<p>Am I declaring here a function such that &#8220;when the program dereferences [it], it has the type [int]&#8221;?  No.  Even if that made the slightest bit of sense semantically given that trying to dereference a function with the unary &#8216;<em>*</em>&#8216; operator is incorrect, it is not what I&#8217;m doing.  I&#8217;m declaring a function that has a return type of &#8216;<em>int*</em>&#8216;.  Not a return type of &#8216;<em>magic value that if I put a star in front of it will give me an int</em>&#8216;.  If we move to a language with slightly different syntax, like Objective-C, the problem with the convention becomes even more pronounced.  For instance:</p>
<pre class="brush: cpp; title: ; notranslate">- (NSString*) toString;   //this is a valid function declaration in Objective-C
- (NSString) *toString2;  //this will make the Objective-C compiler very, very sad

- (void) functionWithAString: (NSString*) string;   //also valid
- (void) functionWithAString2: (NSString) *string;  //not a chance</pre>
<p>Objective-C does an excellent job of highlighting the problem with the standard convention because in Objective-C the return and parameter types in function declarations must be enclosed within parenthesis.  And the asterisk must be included in the parenthesis with the name of the type, because it is part of the type of the object, and not part of its name as the standard convention tries to imply.  </p>
<p>And that&#8217;s the other half of the justification that is used to defend the standard convention; that by &#8220;hiding&#8221; the pointer type so that it looks like part of the variable name developers (in particular, novice developers) can use pointer types without having to really understand or think about pointer types.  This is bad for a couple of reasons.  First off, it&#8217;s trying to twist the semantics of the language in a way that is not accurate.  And more importantly, it discourages (and/or delays) developers from taking the time to understand what pointer types are and how they work.  Yes, pointers can be confusing, but if you&#8217;re going to work in a language that includes them then you need to understand how they work.  How they really work; not just how a confusing coding convention tries to make it seem like they work.</p>
<p>So at the end of the day, the asterisk character in C and C-like languages is part of the type being declared and not part of its name, and it&#8217;s time to start putting it where it belongs; with the type.  A bad convention should not be allowed to stand just because it is the convention.  Write code that intuitively matches its semantic meaning in the language, not code that is designed to trick people who don&#8217;t really understand how pointers work into being able to work with them anyways.</p>
<p>Lastly, and only somewhat tangentally, the following are all examples of very bad coding style, and you should not write code like this no matter where you put your asterisks:</p>
<pre class="brush: cpp; title: ; notranslate">int x, y;    //no
int *x, y;   //bad
int* x, y;   //not any better
int *x, *y;  //you get the idea... 
int* x, *y;
int x, *y;</pre>
<p>Instead, simply do like so:</p>
<pre class="brush: cpp; title: ; notranslate">int x;
int* y;</pre>
<p>It&#8217;s not like you pay by the newline when you write code.  Limit your variable declarations to one-per-line.  Trust me, you&#8217;ll write more readable code that way.</p>
]]></content:encoded>
			<wfw:commentRss>https://codethink.no-ip.org/archives/270/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
