Coding Wrongs in 2015

The Grotty State of the Coding Union

Taking stock of what’s changed in the last 5 years of coding I have come up with the following list of ten items that still make all our lives difficult for absolutely no reason. It has taken me all of … no time at all to come up with this list, which I think speaks volumes on how pathetic coding advances have been.

1. Single Buffer cut/copy/paste

I solemnly promise to copy-and-paste responsibly with this. I have no problem with having one system-wide clipboard that uses <Command-C> or <CTRL-C>. Back in the 19…, umm, back in the day, I used an app that had multiple clipboards which allowed me to reduce mouse travel and window switches. A real timesaver and headache reducer. I don’t know why we can’t have the same today. How about <Command/CTRL-Shift-C> + <Number Key>? If you like mouse-driven editing more, then how about <Left Click> + [Paste] and <Left Click> + [Paste ->] + [Paste 1] through [Paste n]. If that’s too many clicks, make the menu editable so that you can have the first 3 (or whatever) paste commands in the first menu. If you can’t remember what’s in buffer 8, don’t sweat it and don’t use it.This should be a no-brainer.

2. Spellcheck

Sabrina, Genie, Hermione, and Wytches need not apply. Let’s see: we have phones that spell check my texts and emails, able to add words, and make suggestions for typos; we have editing apps that know when I don’t use a local variable, highlight comments, and have context sensitive help. Is it really that hard to apply spell check to comments, auto add/remove variable names for spellchecking, and check code for mis-typed variables? I think not.

3. Procedural Programming

If we want advances then we need to make them end. See what I did there? Yes I’m very clever, aren’t I. Why can’t I just ask for something and get it? The neighbor has SQL, what have we got? Enough with the whining. When writing an app I am working within a specific eco-system. I would much rather spend my time defining the scope of something than spelling out every detail for getting that some data, or working my way around all the cases the other guy didn’t think of. Do I really need to write “oneCompany->Customer(“Smith, Joan”)->Addresses->MailingAddress()”? I would rather have GetMailingAddress(“Smith, Joan”) and let the compiler and runtime environment figure out the right code/steps. This way I can spend time on “real” work and exception handling. Yes, I can build the code into the app to do this. Should I really have to? For every app? For every object in the app? For ever and ever? Debug them for eternity? Sounds like Hell to me. (Nope, feature not implemented yet … heaven still waits)

4. Data store abstraction

Finish these sentences for me: I want to store in the database because…; I want to save to file because…; I need to break the data apart because database 1 and 2 are storing…; We are out of disk space because…; We’re slow because the DB needs… What do these all have in common? Someone, somewhere is making, has made, a wrong decision and that’s causing, or will cause, problems shortly. Part of the reason for this is that storage problems can get complex and solutions difficult to implement. Why not define storage options in an app in terms of what’s needed and what’s available instead of targeting one system versus another and making a wrong choice. For example, transactions go to the database, session data goes to shared file store, permanent data goes to another database, upload results come from an HTML request, and so on. Yes, this is all very abstract, but then again this isn’t an out-of-reach case of abstraction. Databases are configured to handle short lived transactions or long term storage, file systems can be slow or fast and small or large, services can be local or remote, etc. This differs from “transDatabase->StoreTransaction(<user data>)” by not caring in the code what the end storage system is “transStore->Store(<user data>)”. A small difference until you want to change where your transaction data lives; going from a file store to a database for example, or going from one database that has a general configuration to two specialized databases. Yes, this can be handled by writing custom code, and an HTML parser could be written in only Assembly code. It may be fun at first, but the bloom wears off.

5. Typing

I think this one is my favorite :) . Write code without typing? Isn’t that what 4GL, 5GL, or xGL languages supposed to be (where x is your favorite number)? Yes, that is what those xGL concepts are/were all about and I hope never to see them again. I think that the evolution to coding should be away from typing and more towards “knowing” what you want. How many “for”, or “while”, or “foreach” loops have you written? With local variable indexes? Have they been nested inside other loops? What’s been different among them? I think the answer to all of these questions except the last is ‘many’ and ‘little’ for the last. To be clear, I am not talking about right clicking to have a loop added, or replacing the ‘for’ language construct with a function, but getting rid of the fluff that’s just adding to what I type and adds nothing to clarify or functionality. I am not talking about what is inside of the loops either.

It’s example time! I need to loop over array variable rawData, what are the chances I don’t want to index the loop? Will I really iterate over rawData inside of this loop? If I have a 2-D loop, will I really be iterating over the outer array inside of a loop that’s already iterating over the outer loop? Of course the answer to the “will I really …” questions are ‘yes occasionally’, but for the majority of the time the answer is ‘no’.

Enough of picking on loops (I have skipped over numeric iterative loops and their ilk since they are an array by another name). Where else am I typing too much? Comments? Perhaps, but I addressed comments in another post and I think they are critical to good code, so I think not. Type declarations? Yes. “Hey compiler, can’t you see how I’m using the variable and assign a type based on that? You know everything else about my code.” If the compiler assumes an integer and I’m assigning a float to it without being specific about type conversion then I should get an warning/error regardless if it’s a compiler assumed Integer or I declared it that way. If you aren’t using a strongly typed language, like PHP for example, you are already encountering this concept and need to cast floats to integers when you specifically want that. With a language like C# the compiler can assume and make a very educated guess; if overrides are allowed and applied, there shouldn’t be any loss of functionality. In fact it would strengthen C++ to have this since you couldn’t assign pointers to integers with all of it’s attendant horrors. Besides, isn’t a compiler’s purpose to figure out what I want it to do? Note that this is different than auto types or lack of types. I personally think strong typing is a good thing; there is still the auto type for the rare exceptions.

This is running long so I will just list other typing issues: comments (heh-heh, I promise I’m not backsliding on my previous post) should have pre-defined style templates that are mandatory to fill in (saves repeatedly typing in the standard stuff), meta-analysis to detect copy/paste code so that it can be addressed (prevent bad coding practice — fix it once so someone else doesn’t need to type more to fix it), Datastore abstraction (listed above in its own section), code complexity detection so it can be addressed (code obfuscation is not a good thing — this appears to be the opposite of less typing but isn’t when maintenance, enhancements, and such are considered), many if-then-elseif statements together replaced with a switch that allows conditional logic, the same as ‘if’s, in the ‘case’s (change the language if strings can’t be handled [C++ that’s for you] and break out those conditionals for me Mr. J.I.T. Compiler, you’re smart), auto hash values on strings and objects for quick comparisons when needed (why is strcmp still needed? How about myString[1–7] == yourString[1–7]? and case-sensitive: myString[1–7] === yourString[1–7]? Don’t know the string length: myString == yourString? Ambiguous? I don’t think so; if yourString is really an object the compare should fail, and, why aren’t you checking your inputs?), and others. Make your own up. I give you permission. If it’s not any good, then it won’t be used.

6. Code Files and Version Control

Files on disk? Such a quaint concept. Similar functions and procedures stored in a file on disk? Aww, that’s so 20th century. Unfortunately this is still the prevailing method of coding. Let’s say I have a class that is responsible for matching image points as part of stereo-pair-analysis. As one can imagine, such a class can get very large since there are many aspects to finding the matching points. Exactly how the namespaces and classes are broken up are, in my mind, irrelevant; one would probably want a top-level namespace/class called “StereoPair” with another (among many) namespace/class called “MatchPoints”, and so on. Currently we need to make a decision on what methods we need to put in which files. Do we keep everything for one class/namespace in one file, or do we break it up? When does a file get too large to manage? Imagine instead that we just retrieve the pieces we want on demand. If I want to see the code for matching points? I select the class (formerly know as the file MatchPoints.php) and get the list of methods and members. I can then either select a method or member to look at and scroll from there. As I scroll, more methods and members show up. If I want to see what a specific method does it gets pulled in and I see it. No longer do I need to break up files because they are “too large”, or because they have the “complex algorithms”, or whatever the other criteria are. We declare scope already so we can also browse by scope. We already group like methods together and comment them that so we can make the comment an attribute instead. Also, since source control is object based it can also be used to determine linkages and we can browse by those as well. When ready to build and deploy, pull down all the objects needed into a file, multiple files, or whatever; we don’t care nor should we have to.

7. Language based silos

We are so close to putting this monstrosity behind us, and yet so far. To be honest, I have trouble understanding why we’re still here in “I am PHP, you are <fill in the blank>” land. Is this the 2nd grade still? As far as I know, unless physics has changed, every piece of code running on my iPhone uses the same machine language. In fact it probably uses the same assembler language constructs. We can also, probably, safely go one level higher since it’s a closed platform and assume that it uses the same bytecode/IDL that is compiled or interpreted. Decades after Java showed us that we can write once and run anywhere we still can’t have Java talk to C++ talk to PHP talk to C# talk to whatever without jumping through hoops. Why can’t we all just get along? Why do I need to port an algorithm that optimizes drawn freeform points through velocity, and is already existing in C++, into PHP code? Sure I can extend PHP to include my C++ code, if I can figure that out (yes I have figured that out and it’s not pretty whether it’s as an extension or built in). I would much rather have bytecode that defines the interface (map this to that) and gets added to PHP or any other app I’m building. Shared libraries (.so or .dll) are a nice separation but aren’t what I want or need. “You have all the data you need right there!”, I say out loud. “Work, darn you!” For the record, stronger language is brought to bear. I started this section with Java as the example, but I’m not interested in cross-platform here.I just want to write something once, and be able to use it wherever I need to, without having to re-write it, or jump through hoops to get it into another application I’m building. It is all just code anyway, right?

8. UI programming

What do X-Windows, GDI, and OpenGL have in common? Trick question! Nothing (well, almost). What does XHTML have in common with them? Everything, it runs on all the platforms that use the above, and more. So why am I needing to choose between a browser or native UI? Since when isn’t a combo box a combo box, a list box not a list box, a text control not a text control, and so on? Let’s face it, the browser UI concept is working out and is arguably much more powerful and flexible than the native approaches. I say we totally embrace it and move on. On Windows we have .rc files that define the UI. In browsers we have .html files. On Mac’s we have resource forks. In browsers we have html files. The concepts aren’t so different; we have a “place” where we define the UI and other places where we define the stuff that uses the UI (.js, .cpp, etc). If I want to program on Linux and I’m a Windows developer, I need to learn a whole new UI space that looks nothing like what I’ve seen before. Embracing the current UI standard fully would allow the transitions to occur more easily. Yes, I am suggesting we compile XHTML into bytecode or native constructs or something else in such a way that the developer doesn’t have to care.

9. 2-D UI

I remember the first Duke Nukem with its layered 2-D sprites that gave a 3-D effect. Later came Paper Mario and Nox. Now I have apps on my phone that also pretend to be 3-D; apps such as Bastion and Temple Run with it’s descendents. Most true 3-D is on gaming consoles and some desktops. In the work environment one needs to be using CAD to have a 3-D experience. We live in a 3-D world (yeah, yeah, 4-D, alright, keep reading) so why is our computer experience so 2-D? I understand that right now it’s work to get 3-D into apps, so lets change that! Let’s start with true 3-D buttons and other controls. Make it easy to mix 3- and 2-D and we’ll be on our way.

10. Lack of same platform interoperability

Why oh why do I have to copy and paste the results from a database query into a spreadsheet so that I can graph? If I’m in a spreadsheet why can’t I pull up my Postgres widget, run the query, and populate the cells? If I’m in pgAdmin why can’t I make the cells of the results act like spreadsheet cells? I already have pgAdmin and Excel on my computer, so why aren’t you guys getting along? Yes, I can query Postgres from Excel, but have you tried to set it up? I have already defined everything needed in pgAdmin. Why does my spreadsheet require me to not only configure the database connection again, but also to configure an OBDC driver? Why do I need IT to configure another app to make the connections for me? I want to focus on the work to be done, not wait for IT, so I copy and past, every time, forever and ever, day in and day out. Oops, missed a cell, time to copy and paste again. Believe it or not, there are better things for a business to have people do than cut and paste. Such as data analysis and revenue forecasting.

Perhaps a way to think of this is to use a browser as the model. I have all my tabs that represent apps in a nice row. Maybe I have several browser windows up as well, each with their sets of tabs. Believe it or not, the different pages can communicate with each other. Try opening up Netflix in another tab after logging in. See, you are logged in already! Same with Google and many others. Now lets say you have 3 spreadsheet pages open in different tabs and a database query window in another tab, you can see that it probably would make sense to tell the spreadsheet to grab the data from the database tab. This happens by telling the spreadsheet to grab the data, select the data from the database, enter the row and column (or click) in the spreadsheet where the data goes, and … you’re done! Remember, it’s your data and you already trust the spreadsheet and the database so why the obstacles? Believe me when I say that much harder coding and standardization problems have been solved.

Conclusion

Have advances been made? Yes they have and I like some of them a lot while others I find are just OK or dislike. Right now we each have massive computer power at our disposal that was unthinkable 5 years ago; more cheap storage than ever before; faster everything; slicker monitors and multiple monitors; clouds, arrays, interconnectivity; free AI engines, free databases, free web servers, free languages and tools, all kinds of free; cross platform standards. It’s a good time to be a developer geek. It’s a good time to be in technology!

So why are we so stuck in the muck with these simple things, of which I’ve identified 10? I don’t know, but now that you’ve read them, go and create them, use them, demand them and life will become better.