The Education of a Programmer (Me)

Just another WordPress.com site

The value of slow coding

When I took my first programming class going after my Master’s Degree. My instructor then, John, told all of us that if we sat down to code and wrote 100 lines of quality code in an 8 hour day that we were really great programmers. At the time, I thought he was being somewhat facetious. I’ve worked on projects where I turned out several hundred lines of code in a day which was ultimately deployed and considered useful.

Then wisdom followed knowledge. I know how to code. I can figure out what I’m after, write it, and it will pass tests and it will work, but I also learned from John to re-visit my code and always try to make it better. Whether that’s more memory or processor efficient, or just generally create a better algorithm to do what I need to do; it didn’t matter, just to re-visit the code after I’ve left it alone for a while.

Now I’m working on a project and I realize that in the last two days, I’ve written maybe 200 lines of usable code, other than metadata code in wiring up a database to a web app which ensures better type safety, etc. That’s the stuff I write without thinking and while it’s necessary, it’s not the most stellar code.

This morning I found myself really proud of 4 lines of code. It took me some thinking and research to write 4 lines, but in the end, it was 4 good lines that did what I wanted and were well-crafted. So, now I’m realizing John was really right; slower coding produces better results.

Weird Font Post

Ok, I know that I usually write book reviews or about something I’m coding, etc. This time, I’m writing about something a little different; fonts. I admit, I’ve always been fascinated by them. I love the written word and have always studied orthography when I was in my Linguistics program. So it serves to reason I would be just as fascinated about fonts. I almost added a graphic arts program to my current mode of study just to have a chance to learn how to build my own fonts. Well, one font anyway.

I write programs, so I stare at a lot of code and I have searched through many many fonts, trying to find one that made me happy when I had to read so much code. I’ve seen many which were close except for something which would drive me to distraction. Maybe it was the curve in the lower case l or the lower case i. Maybe it was the dotted zero. (I even write a slashed zero in handwriting, thanks to my wife.) Whatever it was, it never fully felt right. Then I stumbled upon Input. The thing which stood out immediately for me was the option to customize the font to what I liked. They had options for miniscule a, g, i, & l. They have zero options, curly brace options, and asterisk options. Basically, I could make my font the way I wanted it to look.

Then as I would read about the development, I emailed the designer and got a very nice return email which invited me to continue to note things I’d seen in the usage.

It comes in the standard Mono, Sans, and Serif, with several weights and several kerning options, (regular, narrow, condensed, and compressed.) So to have it for Visual Studio, I make my own custom variation (InputMonoCompressed) and it looks fabulous, I can read it all day, and then I can use the other variations in other apps as I see fit with no headaches.

Best of all, you can use it for free in certain circumstances. However, if you want to use it for commercial publication or for your website, you have to pay for it. That’s fair in my book. When I can afford it, I might just buy a license to use it on a personal website. Until then, I’m going to gratefully read code in it while I work!

Out-thinking, but not outwitting myself

Like any good programmer, I keep trying to re-factor some of my code to make it more efficient, better, etc. Now that I’ve become more comfortable with Linq to EF and Oracle together, I realized it would be time to re-write our Hot Calls program. (Not what you think folks). Even though Syncfusion has come out with one of their Succinctly series books on NHibernate, I don’t know that I’m going to make the switch just yet. I would like to try it as a test some day so I can get familiar with it, in case I ever have need of it.

However, I started with the Poller which scans a database of incoming calls and takes the newest calls to a series of temp tables for the logic program to handle. This program doesn’t really lend itself well to either EF or Linq for that matter; so I’ve written the SQL by hand but I still wanted to tweak it. The headache was the first place which lends itself best to the tweaking was the exception handling. Finally, I’ve wrapped my head around overloading my functions enough that I’ve built workable overloaded mailing and logging functions which I can reuse as I’ve wanted to do for some time. Doing this appears to remove nearly 40% of my code base. That is going to be a huge difference across all of these functions. I know I have more re-factoring to do along the way and soon it will be even tighter. (Don’t worry, the commenting is still as verbose as always.)

Yay! Hail the little victories here and there when you can get them.

Book Review – Becoming Functional

I’ve recently been reading Becoming Functional by Joshua Backfield. As usual, the disclaimer is that I received a copy of the book for free in return for the review.

I was interested in this book, primarily because I have always been of the opinion that some of the code I’ve written for a couple of programs I’ve developed could be better written using a functional model as opposed to the traditional declarative programming model I learned in school. After reading this book, I’ve realized my instincts are better than I thought and that I’m right in that belief.

Mr. Backfield does a very good job stepping the reader through a fictional company where, as a developer, you’re trying to make some of their back end programming more efficient and more responsive to the user. He starts by walking you through the company’s code and then refactoring it step-by-step to more and more functional paradigms. Along the way, he does a good job of explaining functional programming in brief and how factoring the functions can make everything work more efficiently.

When I read the book for review, I only had the first six chapters available, but the chapters on immutable variables and recursion were enough for me to be sufficiently impressed and to have some ideas on where to take my own code. I am certainly going to go back and finish the book and work my way through the code.

Even though the code examples are in Java and Groovy, it’s not difficult to see how to change them over to C# and possibly F#. (For programmers like myself in the ASP.NET world.) With this in mind, it won’t be hard at all to work out the refactoring method by method.

Overall, for an experienced declarative programmer, this is a great introduction and a good guide to adding in functional concepts where they are called for. For less experienced programmers, this is a great way to look at a new paradigm while gaining a good understanding of how it can work in the real world. I heartily recommend the book for anyone interested.

Step by step in Vim

I kept reading Ben McCormick’s blog entries about Vim and am going over other tutorials and books I have in my collection and I felt comfortable enough working on a file to never take my hands off the keyboard and NOT go into insert mode as the default way of doing things. For me that’s a bit of a win. I did a few significant updates to a behind the scene page so now I feel safe enough going from there to start building and having more fun with things to see just how comfortable I can get. 

I know it’s always one day at a time and that’s how you learn. It’s just fun to make some progress and remember the ways to do something more efficiently and go from there. (Yes, I’m a geek and things like v18ld to pull a piece of a string out of a url is pretty cool to me!)

 

Next step in the evolution and education

I spend a lot of time in front of a keyboard. That’s the nature of programming. Since I also write websites, I also spend a lot of time on the web, reading about programming and the like. 

Recently, I ran across a wonderful series of articles by Ben McCormick on Vim. Here is his first post in the series. He made me think about a few things, including the fact that though I have a couple of editors I love and use a lot in the Windows world, I have never mastered Vim myself. (Now, for those of my readers who are Emacs fans, I’ve never mastered it either, but in trying to use either one, Vim seemed easier to me, so I’ve tried several times to learn it as opposed to Emacs. No flame wars here please!) 

So I’m going to use his posts as inspiration and the resources I have available to me so I can really make an effort to learn Vim and learn it well. The truth is, it should not matter what computer I am at, I should be able to sit down, fire up Vim, and be able to work on a file regardless. I can’t do that right now and that bothers me. It’s not about programming chops or anything like that. It’s really about the ability to go where I need to go and be as productive as I can me. Yes, I know that I have Visual Studio or Sublime Text available on my normal rigs and I have sublime and Vim both on a flash drive, so for a Windows OS, I’m relatively well set. However, I came from the Linux world. (Yes, I actually have worked with Linux as a primary desktop OS since a 1.2 kernel and the fact that I have not mastered Vim and LaTeX do make me hang my head some days. I had more success with joe and nano.)

So the goal for the second half of the year is to learn both Vim and LaTeX well enough for every day usage. I know that I need to learn them and I know they will be beneficial for me to learn and master. 

My question for you my readers, if you are out there, is what other resources do you know of which might help? I know about vimtutor and I have a few eBooks on PDF which will help me. From there, it’s time to get cracking and any resources are fantastic.

Packt Publishing Sale

Disclaimer – From time to time, I do reviews for Packt Publishing and in return, I receive free copies of the books I review. I also write blog posts like these to promote their sales from time to time. I do this because I like the quality of their material and with more business, there are more opportunities for me to review books for them.

They are now celebrating their 10th anniversary and they are running another sale, hence the reason I’m writing this now. From the 26th of June until the 5th of July, Packt is offering all of their eBooks and videos for $10 a piece. While they are normally affordable, this is a very good sale. If you are going to go check it out, and you should, use this link so they know you came from my blog. Or click the graphic below!

 

10 days 10 years - Home Banner

Even more inches and Github Commits

Well, Bugs and I, from my previous post have made many more strides on my “wascally web app”. (Pardon the pun, but I’m full of them when I’m trying to make sense of this stuff.) Now, it’s deployed and useful. I’m at the stage, now, where it’s fun working on it and making the incremental improvements which ensure that my admins will not only use it, but will like how it comes out.

The nice part was solving each of these incremental mysteries and then improving it without saying, “I can’t do this, solve it for me,” on the various boards. I added in a search feature for subscriptions based on the user id so I can grab each users subscriptions. It was built in response to not being able to delete a user until the subscriptions were accounted for because of foreign key relationships. Later, read today, I changed the table structure of the underlying subscription table to enable cascade deletions so when you delete a user, the database also deletes the user’s subscriptions.

I’ve left the ID to be set by the admin because it works and because I can reuse IDs that way for deletions. Oracle’s default behaviour is to reserve 20 id’s at a time when you write an incremental ID trigger. So this seems to circumvent that. It’s a little more work from the admin, but it’s not too onerous.

I fixed the name entry into upper case through javascript. It works and it’s not problematic, so I’m happy about that.

I built my dropdown lists with a little bit of help and then added those into the page along with finding the IE problem. It turned out to be client side and with a little adjustment to the quirks mode, it’s all good. So this is, effectively, done and deployed. YaY!!

Getting Ever and Ever Closer

As I type the title, I hear Bugs Bunny, “Slowly he turns, step by step, inch by inch.” That is how this web application feels like. Step by Step, Inch by Inch I make some progress. I finally was able to break through the ODP.NET issues. I broke down and used the managed driver and then insured it was registered in the machine.config files for both x64 and x86 architectures. To me, this feels a bit like overkill. I had set the .dll to Copy Local=”true”, so IIS should not need to access the server’s copy. (Though I had already copied there just because I had learned that valuable lesson quite painfully recently.) Be that as it may, that is what it needed. After that came the ORA-12504 error. It couldn’t find the proper tnsnames.ora file. However, that is a relatively easy fix. I just changed the Data Source = from the alias to the full TNS name. Violá, the app likes the change and now it works.

Of course, I wouldn’t be discussing “step by step” if that were the end of things. Version 1 in classic ASP allowed you to filter a user list by the sponsoring agency. I didn’t include that this time. However, my users are quite content not to have it as long as they can have a search box which allows them to query the user base. It didn’t take me too long to find this page. I modified the basics to fit what I wanted and it works. I had to go back and make a modification and that was to ensure the search always hit the database in upper case. However, I’ve used ToUpper() many other times, so it was a quick fix.

The next step has arrived. How do I ensure that the data which is being entered is written into the database using only upper case for the subscriber names? I’ve worked through a couple of different solutions and they haven’t panned out. In fact, the whole thing has shown me that the ID field trigger on the database isn’t actually catching on that it needs to fire and the application doesn’t need to set the ID. So for now, I will set the ID in the /Users/Create page. It’ s not my preferred solution, but it’s on the list of enhancements.

Also on the agenda are to see why the site renders perfectly in Chrome and Firefox, but won’t render in any version of IE (I run 11 myself), but will render perfectly in IE when I use my IIS Express configuration locally to test the site functionality. I tried to alter the properties at the solution level, but garnered an error stating the .NET versions don’t match. Back to that drawing board. I need to build radio buttons and/or drop down lists for /Users/Create and 3 fields which need to be restricted as to their possible entries. So far, everything I have researched shows it’s really easy, but doesn’t work.

And, if I can do it, make sure that the first and last name entries go into the db in upper case, not lower or mixed case.

Simple? Maybe. But it’s taking time to research since this is the first ASP.MVC app I’ve built.

Book Review – Microsoft Visual C# 2013 Step by Step

I’ve recently been reading Microsoft Visual C# 2013 Step by Step by John Sharp. As usual, the disclaimer is that I received a copy of the book for free in return for the review. I’ve not linked to the book because I blog as part of O’Reilly’s reader review program and recently Microsoft Press books have been removed from their site. Out of courtesy to them, I am not going to link to Microsoft’s site for the book.

The book is aimed, as you read it, for programmers who are wanting to get a foundation in the basics of C#. As such, the book is a good reference work. It takes apart each of the different parts of the language and shows you how they are used in basic format. The first part of the book introduces you to the language, it’s absolute basics, and Visual Studio. The second part, getting the object model under control. Part 3 extends it, and finally, part four shows you how to build something simple for Windows 8.1; as that is Microsoft’s application focus currently.

Overall, Mr. Sharp does an excellent job describing the basics. If you’re a more experienced programmer wanting to see what’s new in the language, this isn’t really your book. But that’s not a negative. It’s not designed for that level of programmer. The examples are clear and concise. However, my one concern is that, as with most beginning books, what you’re learning along the way doesn’t build on itself until the final portion of the book when it all builds at once. However, if you’re going to be new to C# and you’re not coming from Java, this is certainly a good book to start with.

Follow

Get every new post delivered to your Inbox.

Join 810 other followers