RSS
 

How to Suck at Debugging

25 Feb

From my own personal experiences and those that I have picked up from people around me over the years, I have come to the conclusion that a lot of people really suck at debugging (myself included).  Here I have outlined some of the easiest ways to never fix anything.

For those that don’t properly understand sarcasm, you can pretty much do the opposite of what I say here.


Always Assume You Know Why It’s Broken

Only new and inexperienced programmers need to actually break into code when something goes wrong, good programmers can tell the problem just from the output.  Never investigate an issue, especially when you don’t know what could be causing it, just fix the problem there and then.

Once It’s Fixed, Don’t Waste More Time Testing It, Just Check It In!

Considering the unlikely event of a programmer such as yourself already making a mistake, and the known fact that lightning never strikes twice in the same spot, just check it in and rest in the knowledge that it’s guaranteed to work the second time round!

Intimidate The Problem By Staring At It

Don’t be a wuss!  A real programmer never gives up on a problem until it’s solved.  Just sit there starting at it until you figure out what’s wrong and don’t dare move or think about anything else, because if you do, you’ve already lost.

It’s Not Me, It’s Someone Else!

As soon as you see that the problem may be even remotely related to a piece of code that someone else has written, drop everything as you’ve obviously found your culprit.  After having a moan about them to a fellow colleague, just continue with whatever it was you were doing before hand and don’t let anyone know the status of the issue, after all, it’s not your problem any more.

Just Keep Retrying It, It’ll Work Eventually

If something doesn’t work the first time, just keep retrying the action as it’s probably just a temporary error.  If after a 30 tries it still doesn’t go away, put it to the back of your mind and get on with something else while you wait for it to fix itself.

If It Works For Me, It’ll Work For You

Occasionally, some fool will try to run your code and it won’t work but why should that concern you?  When it was on your machine it worked fine so it’s obviously something stupid that they have done.  Just kindly let them know that they need to figure their own problems out as you have enough on your plate without having to deal with actual users.

 
 

Git vs SVN, Which is Better?

05 Jan

After a hectic Christmas of stuffing my face with Turkey, Cake and Chocolate, I have had to power on my brain again and get back to work.  Before Christmas, high on the sugary goodness of Git branches, I disconnected all my SVN repositories and got Git set up instead… maybe not such a good idea after all.

Git is a powerful platform, most likely more so than SVN, but it’s just not as easy to use.  All the knowledge I pulled up from the tutorials mentioned in my last post has faded and I am struggling with even simple tasks.  I’ve taken it upon myself to go over them again and I am starting to feel a little strained at all the extra steps I now have to take when opposed to SVN.

SVN:

  • Right click, click Commit.
  • Enter message in provided box.
  • Check files in nicely formatted table form.
  • Click Commit again.

Git:

  • Right click, click Open Git Bash.
  • Type:
    • “git add .” ensuring that the junk I don’t want is ignored.
    • “git commit -m ‘Some Message’” without support for easy formatting the message.
    • “git checkout master” to return to the master branch (good practice).
    • “git merge dev” or whatever the branch was before (good practice).
    • “git push origin master” to commit it to a central repos.

git-logoIt’s not Git’s fault that it’s like this, SVN was once the same and only with time did the excellent tool support come about.  I do think Git is the future as they keep plugging the gaps where it doesn’t measure up to SVN but it’s whether now is the time to use it?  I’m not averse to typing, it’s just it takes a lot longer and isn’t as user friendly as a big box that I can just click on.

I have one more thing I’d like to try before I commit to either one for the time being and I will follow it up in a post shortly.

 
 

Git it right SVN!

03 Dec

I’ve just completed an interesting set of tutorials on Mastering Git by TekPub and I have to say, I am very impressed at what Git has to offer.  For several years now, I have used Subversion to do my source management and it’s been a great little tool but I have also had a lot of problems with it, days of lost work after a dodgy merge being one of them.
git

The most interesting thing I found about Git was how it approaches many source control tasks in a radically different way to Subversion and other source control systems.  In Git there is no concept of a master repository, overruling all your source code. Instead it employs a more distributed approach where everyone with a git repository clone is effectively the master repository. Don’t get me wrong, this doesn’t mean that you cannot have a central repository, just that it can just as easily be in multiple locations or even just on your local box, all without losing the power beind source control systems.

Being used to Subversion, I found Git to be a bit of a turn-off when I first saw it – the command line looked scary and I decided not to go with it “because it was too hard” – but it’s not.  I would recommend the tutorials on TekPub to anyone interested in expanding their ’source control’ mind as once you get the hang of it, you won’t regret it.

 
Comments Off

Posted in General Banter

 

Censorship!

20 Nov

A lot of my older posts have just dissappeared from the site because I have decided to keep this blog professional. It’s of no service to anyone to hear me complain about my old job or praise my new one and the focus should remain on providing something that might actually benefit from reading my posts. Despite this, I will continue to add my personal obstacles to the website but will just keep it more focused.

logo-breeze

So over the past 6 months, I left my old job at Frontier – as I previously mentioned – and have been working at Opportunity Links which has been a refreshing new start. I have also learned a great deal about website development and produced a site, free of charge, for a company called Breeze Photos in Australia. Breeze is run by a family member and sells canvas prints or photos on canvas, depending on how you like to word it. In doing this website, I finally got to use (and improve) my MVC engine ‘quartz’.

I am now working with a colleague on a very exciting new project that will hook into iWishGifts when it’s released.

 
Comments Off

Posted in General Banter

 

Encoding with GetBytes(), GetString() and Convert() in C#

16 Sep

After a much troubled and confusing morning, I would like to share some information my colleagues and I figured out about string encoding in C#. While what I am about to say may seem very obvious to some, we felt it would be a good idea to share what we learned with the community so, hopefully, fewer people will have to struggle with it.

Our issue was encoding between the string type and byte arrays and vice versa.

Consider this example:

// Start with our unicode string.
string unicode = "Convert: \u10A0";

// Get an array of bytes representing the unicode string, two for each character.
byte[] source = Encoding.Unicode.GetBytes(unicode);

// Convert the Unicode bytes to UTF-8 representation.
byte[] converted = Encoding.Convert(Encoding.Unicode, Encoding.UTF8, source);

// Now that we have converted the bytes, save them to a new string.
string utf8 = Encoding.UTF8.GetString(converted);

Now if you understand encoding, you will know that is wrong, but as people quite new to encoding, it looked right to us. We were under the assumption that the bytes put back into the string were exactly as they appeared in ‘converted’, which was **incorrect**.

**The key point we were missing, which was making this very confusing, was that string types are always encoded in 16-bit (2-byte) Unicode**. This means that when we do a GetString() on the bytes, they are automatically being re-encoded into Unicode **behind the scenes** and we are no better off than we were in the first place.

Now that this is understood, in our case where we were sending data from one point to another and we wanted to send the data in UTF-8. The function call is irrelevant but it took a string as the only param:

// ... ENCODE AS ABOVE ...

MicrosoftFunc(utf8);

When we started to get character errors, and double byte data at the other end, we knew something was wrong but at a glance of the code we had, we couldn’t see anything wrong. After learning what we have explained above, we realised that we needed to send the byte array if we wanted to preserve the encoding. Luckily, MicrosoftFunc() had an overload which was able to take a byte array instead of a string. This meant that we could convert the unicode string to an encoding of our choice and then send it off exactly as we expect it. The code changed to:

// Convert from a Unicode string to an array of bytes (encoded as UTF8).
byte[] source = Encoding.UTF8.GetBytes(x); 

// Send the encoded byte array directly! Do not send as a Unicode string.
MicrosoftFunc(source);

Summary:

So in conclusion, from the above we can see that:

  • GetBytes() amongst other things, does an Encoding.Convert() from Unicode (because strings are always Unicode) and the specified encoding the function was called from and returns an array of encoded bytes.
  • GetString() amongst other things, does an Encoding.Convert() from the specified encoding the function was called from to Unicode (because strings are always Unicode) and returns it as a string object.
  • Convert() actually converts a byte array of one encoding to another byte array of another encoding. Obviously strings cannot be used (because strings are always Unicode).
 
Comments Off

Posted in General Banter

 

World of Webcraft

23 Jun

I’m back to work after an extensive battle with a World known as Warcraft. Bloody hell is that game addictive; I’m still not completely free of it but I’m weening off it slowly. I’m on a scale where at one end is a needle packed with all the +70 Spell Power and +32 Resilience you can fit ready to inject directly into your social life and at the other, gleaming and glistening and calling your name softly is the work you have neglected for the past three months. “Don’t worry!” I say, “We’ll be together soon!” and today, “soon” has finally hit. Yes, I have tipped the balance in favour of my old self – just as unsociable but much, much more productive.

Back to the point, I am finally round to start the final phase of the website, which has now been re-christened as a much more speech and search engine friendly iWishGifts.com. The rename has been one of the most motivating factors in getting me clean, it kinda feels like a fresh new project but with only that final 10% to do. With Travis singing sweet lullabyes to me in the background, I think I can do it!

 
Comments Off

Posted in Website Development

 

Opportunity Linked

03 Jun

Yesterday I was offered a new job in Web Development. It’s clearly a step in the right direction for me with all the web-based projects I have had underway recently.

The job is at a government funded, non-profit organisation called Opportunity Links. Now, before you rush off to type that into Google, everyone’s favourite search engine that is starting to find flaws in its search algorithm – but that’s another topic, I would like to ensure that you pick up the correct link as apposed to the incorrect link (which is rather embarrassing).

Okay so they are technically the same company but the place is split into two, the super elite web design team of which I am part of and the “social-working” website of which I am not. Maybe it’s an inside joke or something? I’ll find out soon enough I guess.

I start on the 6th July 2009 and will be no longer using C++ but instead, the much more elegant, C#. I say more elegant because the debugging features that I have seen are phenomenal. You don’t even need to compile your application for your missing semicolon or bad function declaration to be noticed, it’s just there, in beautifully highlighted colours of the rainbow just asking to be fixed before you sit waiting for the error to appear after compiling for half an hour just because you forgot to pay attention to that closing bracket at the end of your function.

They seem very knowledgeable there and I can’t wait to get stuck in to the bliss that is learning, I miss it more than I can express in mere mortal words. Time to study hard and give it everything I have. Keep your daughters hidden and your suit buttoned up because here comes the best damn web-programmer Cambridge has ever seen!

 
Comments Off

Posted in General Banter

 

Systemantics

29 May

I’ve been reading a lot of Joel on Software recently by a guy called Joel Spolsky. He’s already very famous in the blogging scene and you can tell why even after reading a single article. He’s clearly a very clever man with some very sound views on how businesses should be run.

I frequently find myself relating with the examples he uses for bad companies and the things they do wrong with the job I am in at the moment. Okay, so it’s not a Chinese Textile Factory but he really does a good job at enlightening you to the possibility of something greater. I find it extremely depressing that I am working in a company that seems so backwards. We’re meant to be a cutting edge industry but all the fluff that goes on just makes it seem like a dusty lawyer’s office with a very systematic approach to work ethics.

 
Comments Off

Posted in General Banter

 

Spring Fair International, the Aftermath!

02 Feb

Spring Fair International, the home of the innovative new products for the new year. Based in the Birmingham NEC, it’s a place for wholesalers to show off their products to prospective buyers like me.

I ended up going with my girlfriend and spent the whole of Sunday, walking around as many of the football-field sized halls as we could muster. I know I didn’t mention it but it was a last minute decision and I am so glad I did go. We now have a portfolio of fantastic suppliers and some great new products to bring to the table. I also managed to finalise the deal with my good friend Mr. Lynall to have his jewellery collection on the new DIVIRE which should give the company a good head-start.

As for DIVIRE, the product page has been completed and a few of the final design touches are going on. I have booked a week off work just after Valentines day and will be using it to knuckle down and get it up and running, hopefully with a few more products on there than just Mikro Men.

 
Comments Off

Posted in General Banter

 

I’ll Dabs your Monitor!

28 Jan

I have done quite a few transactions with Dabs.com in the past, generally in my younger years, and have generally been quite happy with their services. If you overlook a few of their flaws, such as the inconsistencies in their listings, their poor search system and the fact that their website doesn’t look like it has been updated since they opened about 10 years ago, they seem to be pretty decent company with some great prices. At least that’s what I thought 6 hours ago.

It seems that to Dabs, the concept of a “new” product actually falls under what everyone else classifies as a “working” product. My supposedly “brand new” £210 24″ monitor was far from it. From the moment it arrived, it was obvious that something was wrong. Anyone who’s anyone and has bought an LCD before will know that they come fully sealed with a polystyrene molded surrounding in a nice flat rectangular box. Mine on the other hand was bulging out almost a few centimeters and the replacement tape they had chucked over the original tape to seal it up had completely come off at one end.

Giving them the benefit of the doubt, I opened the package up to take a look.

  • Monitor, check!
  • Cables, check!
  • Software and manuals, check!

All looked good until I pulled the protective sleeve from the screen. On the top of the shiny plastic that Samsung (who are awesome by the way) provide, several medium to deep scratches and lots of scuff marks surrounding it. It didn’t stop there, the same sort of thing was present all over the monitor indicating either a return or some factory refurbished crap.

Once I got in contact with their complaints team, I was offered a return and replacement courtesy of their courier. “Fair enough” I thought but as the monitor is quite important right now, I wanted to know how long it was going to take. 4-6 weeks they said! Now… correct me if I’m wrong but what!? If I had wanted the monitor in 4-6 weeks, surely I would have bought it in 4-6 weeks. How is sending me an obviously used product as new my fault? To make matters worse they then proceeded to “accidentally” close down the window when they weren’t getting a happy customer response from me. I wasn’t rude but hell, I was annoyed!

So yeah… now I have to either live with the scratches or wait 4-6 weeks for a replacement. Want a recommendation from me? Never buy from Dabs unless you like being punched in the face repeatedly. I’ll be forever using Amazon and eBuyer from now on. Both of which are top notch!

 
Comments Off

Posted in General Banter