C# string surprise

My jaw still aches remembering the pain of dropping to the floor when Visual Studio refused to compile

    if (someString >= anotherString)

It complains in no uncertain terms. In fact, it drives the message home by repeating the message, albeit with a different word order.

Operator ‘>=’ cannot be applied to operands of type ‘string’ and ‘string’
Cannot apply operator ‘>=’ to operands of type ‘string’ and ‘string’

What the …?

Coming from Delphi, typing comparisons like that is in my muscles. It will simply do a character by character equality comparison ending at the shortest length or the first mismatch. Only if you want anything more intelligent, like case insensitivity or locale-awareness, do you resort to specialized comparison functions.

So why does C# complain?

Why does it make me use string.Compare when that doesn’t force me to specify ignoreCase or a ComparisonType? After all, C# does overload the == operator. So why not the other comparison operators?

I just don’t get it.

Anybody care to shed light on this?

Posted in General Programming
Tags: , , ,

Hackpad’s reassurance for habitual Ctrl-S pressers

Three decades in software development has given me ample experience with those horrifying moments where the gut-wrenching realization dawns on you that x number of hours of work just scooted at lightening speed into the black hole of an application (or machine) crash.

It’s a horrible feeling.

You know you have no way to recover that work. There is no recycle bin from which to undelete it.

There is only one option and that is to do the work all over again. And hope that the same brilliant insights you had first time around, will come to you again. (Why is it that you always expect the second time around to be worse rather than better?)

Anyone who has experienced this at least once, is likely to turn into a habitual and incessant Ctrl-S presser.

I know I am one. I am pretty bad. I’d say I press Ctrl-S or Ctrl-Shift-S every time I pause my typing for longer than a couple of seconds. Especially when I’m coding, it’s like an uncontrollable OCD (Obsessive Compulsive Disorder). I am bad, but by no means the worst. I have (had) colleagues afflicted with this far worse than I am.

Many web applications, and admittedly many desktop applications, have addressed this auto-saving what you do and providing easy means of reverting your changes.

Not all applications do, however. And there can be good reasons for that. Though I’d say that in most cases sticking with explicit saving is a cop-out. The only good reason I can think of is when saving is resource intensive and auto-saving would interfere with a user’s flow.

Regardless of the reasons for explicit-save still being around, the fact that it is still a widespread phenomenon, keeps the Ctrl-S OCD alive. And while I have grown pretty good at keeping it under control when I know the site or application I am using has proper auto-save, it still sometimes rears its ugly head when it is totally unnecessary.

Most auto-saving apps just ignore the Ctrl-S. Something to be said for that. After all, pressing Ctrl-S is superfluous in those apps.

Hackpad has a different way of dealing with Ctrl-S presses. I like it. A lot. It’s non-intrusive and educational. May even save me from some RSI as it helps reduce my OCD.

Hackpad Response To Ctrl-S

Posted in User Experience
Tags: , , , , ,

Current date and time just one key away in Notepad

Today, I discovered a nice little feature in Notepad. By accident.

I was starting up for the day, opening the apps I tend to use all the time: Notepad for my activity logbook, Chrome, and the usual other stuff. Chrome’s new tab page has this nice feature of displaying eight most frequently (or recently) used websites.

Google new tab page

Except. It doesn’t. Not always.

When Chrome has been closed and your computer has hibernated, slept or restarted, Chrome’s new tab page does displays 8 sites based on old data.

Luckily, there is an easy work around: presssing F5. That reloads the new tab page and then it does display 8 sites based on the most recent “most recent/frequent” data.

That F5 has been added to my “getting started for the day” muscle memory.

Then… Serendipity.

From the corner of my eye, I saw text changing in Notepad. Reflexively, I switched to Notepad and pressed Ctrl-Z to undo it. A lot more text disappeared than I expected. So I pressed Ctrl-Z again to see what had disappeared. Turned out to be a time stamp.


How did that end up there?

Started playing with some keys. Then noticed that the new tab page in Chrome hadn’t updated yet.

Switched to Chrome, pressed F5… Brain clicked. Somehow my previous F5 had ended up in Notepad?

Switched to Notepad, hit F5 and yes, hey presto, a time stamp appeared.

Notepad F5

Never knew that Notepad could do that. Haven’t found any “insert …” menu options or whatever either.

Makes me wonder. Are there any other nifty hidden features in our oldest and dearest Windows’ text editor?

Posted in Tips and tricks
Tags: , , ,

Ends and means

Old quest

You might say my Linux quest failed miserably. I got defeated in the land of unexplained instructions and fairyland errors that had no right to exist.

But, you would be wrong. Using Linux as a platform for a website never was a real goal. It was a means to an end. And means can change while the end stays the same. In my case the end was learning. Mixed with a bit of nostalgia from times when running a site on Linux could have been an end, but would have been a means as well. (That is, a means towards cutting costs except that probably it would have meant incurring quite a steep learning bill far exceeding the price of the license fee saved.)

As learning was the end and getting an ASP.NET5 site running on a Linux shared hosting account was just the means, the quest was a success. I learned a ton.

Apart from the solutions to the problems encountered, which are always nice little conquests, I learned, perhaps again, that I am not cut out to work with Linux or any other OS or application from the land of unexplained instructions. At least, not just to satisfy my curiosity. I like a challenge and I’d happily have continued the quest if I had really needed to do something with Linux. Right now, I’d rather delve into ASP.NET 5 itself than wrestle with the ring in which it is running.

Don’t get me wrong. I like getting out of my comfort zone. That’s a huge part of my “Learner” make up. The point is that I have plenty of more pleasurable ways to get out of my comfort zone.

Sooooo… back to safety (ha!). Back to Windows and learning ASP.NET 5 and MVC 6 in their native wrestling ring.

New quest

ASP.NET 5 and MVC 6 being the subject to learn, it stands to reason that we will be building a web application and who knows, one with its own WebAPI to boot.

First steps:

  • Get the ASP.NET 5 samples running on an Azure Windows VM
  • Get the bare bones web site created for the Linux quest running on that as well
  • Set up the infrastructure for easy deployment of new versions.

After that, it’s a free for all. Any feature is fair game. That said, I do intend to follow a specific structure. Given a feature to build:

  • Is shopping the shelf an option, or perhaps even a “must”?
  • What software design alternatives do we have and why choose one over the other?
  • What contraints do the design of ASP.NET 5 and MVC 6 put on our design?
  • Then “just do it”

So, what features is the quest’s application going to have? What is it going to be about? What is it going to need? Both in terms of “core application functionality” and in terms of “basics you just gotta have”?

What are the questions and challenges people face when they are starting out building a web application?

Couple of things come to mind immediately:

  • Signing in. What’s the use of a web application if you can’t distinguish amongst your users?
  • Billing. I don’t know about you, but personally I’d like to create something that maybe one day I can apply to build me something I can live off. So, yes, billing.
  • Notifications. People don’t like having to log in just to see nothing happened while they were away. So let’s be kind and tell them when something interesting (to them!) happened on the site.
  • Direct messaging. Users can send each other messages through our web application ensuring they can keep their contact details private and still interact with other users.
  • Q&A StackOverflow style (but with less pompousness about what fits their Q&A format).

What else would be worth digging into?
What order should we address them?
Would you be interested in contrasting ASP.NET 5 / MVC 6 with previous versions? Or would you rather just forget about those?

__Please let me know in the comments.__ Apart from the first steps of the quest, I am not particularly fussed about priorities, so let me know and I’ll adapt.

One constraint I am going to put on all this, is: don’t code anything that isn’t core functionality of your application.

For example, when you are building a SaaS enabling self-employed people to bill their clients, then billing would be both “core” (your users billing their clients) and “just gotta have” (you billing your users). In the first case you want total control over what it does and how it does it as that is how you distinguish your application from the gazillion other billing applications. In the second case billing is just something “you gotta do”, and what you need to do to get the bills to your users is not part of their user experience. So shopping the shelf and just coding the integration of your application with a third party service probably has a much higher ROI. After all, even though we are of course capable of doing a better job of it ourselves, we can only spent our time once and spending our time on stuff that provides value for our users is much to be preferred.

If you don’t want to miss any of my future adventures: subscribe below and get every post delivered straight into your inbox.

Posted in Learning

Not quite running the samples on McCoy – my be… Linux VM

The status of the quest to get a bare bones ASP.NET 5 (aka vNext) website running on a shared Linux hosting account:

So now that dnx is running on the McCoy Linux VM, it should be a breeze to get the ASP.NET 5 samples up and running, shouldn’t it? Let’s see.

Referring back to the “Running the samples” instructions, we got stuck at step 3 “Run dnu restore to restore the packages required by that sample.”

Ok. Fire up Leonard on McCoy, change to the folder of the project I chose to use as our proof of the pudding (the HelloMvc project) and run that dnu restore command. Hey ho! This time that command actually starts a whole lot of activity. It looks all nice and dandy, except that it comes to a premature high-pitched screeching halt.

dnu restore crash

What the …?!? Isn’t there anything about this quest that can go right in one take?

At least there is a stacktrace and some debug information: “This usually indicates a fatal error in the mono runtime or one of the native libraries used by your application.”

Should be nonsense of course, didn’t mess with the mono runtime and I didn’t code the sample, so if any native libraries are used by the project, they should not normally pose a problem. After all, can’t imagine the ASP.NET team wanting to shoot themselves in the foot by providing faulty samples. So, it must be something on McCoy (again!)

Then I notice the “1.0.0-beta5” in the folder name. D’oh. To solve our DNX challenges, we upgraded to the latest version. Would it be wise to upgrade the ASP.NET 5 source and samples as well? Well, ya, d’oh! While we are at it, let’s make sure everything ASP.NET 5 connected is upgraded to the latest version. Which means

  • First DNVM itself (as we learned the hard way)
    • dnvm update-self
    • and . ~/.dnx/dnvm/dnvm.sh
  • then DNX
    • dnvm upgrade -u
  • and finally the ASP.NET 5 source with its sample projects
    • git clone https://github.com/aspnet/home

Now, we are still in the ~/home/samples/1.0.0-beta5/HelloMvc folder, while our upgrade just installed 1.0.0-beta7. That’s perhaps being stubborn. The lack of a GUI doesn’t make me want to go hunt for newer vesions. If the version numbering pattern I think I spotted, has some merit, then there should now be a ~/home/samples/1.0.0-beta7/HelloMvc folder. Nope, no such luck. According to GitHub there are samples specific for beta6. So let’s try those. Nope, no luck. No 1.0.0-beta6 folder under samples. There is a latest, but if we don’t have 1.0.0-beta6, then latest most probably wasn’t updated.

Ok, so git clone didn’t do what I expected it to do? It did all sorts of stuff, but it didn’t update to the latest version. No, blondie, of course it didn’t. Well I dispute the “of course” bit, but to update a cloned repository with the latest changes on the remote, we need git pull. Yes. That brought down a whole lot more, including a samples1.0.0-beta6` folder.

So let’s restart the “running the samples” instructions, cd to the beta6 folder and run dnu restore from there. Yes, it starts doing its thing again. Keeping our fingers crossed… And … we screech back to a halt. This time on a different package, one before the package that caused trouble before.

second dnu restore crash

At least it is getting the newer packages. The number on the “Cannot handle address family” is different as well. But the debug information is the same: “This usually indicates a fatal error in the mono runtime or one of the native libraries used by your application.” Working on the assumption that we just addressed the “native libraries used by your application” by upgrading everything that is ASP.NET and samples related, this now points to Mono as the culprit?

Hang on.
Why was I doing this again?
… To run ASP.NET on a shared Linux hosting account.
Why did I want to do that again?
… Because umpteen years in the past Linux hosting was much cheaper than Windows hosting.
… Oh and yes, because I like learning.

The first is moot. Reasonably priced Windows hosting is easily found, even if you get less resources (disk storage, traffic, databases, or whatever) than for Linux hosting at the same price.

The second is still true. And giving up usually is not an option for me. But in this case, I think I have had my fill. So, sorry, but I am calling it and throwing the towel into the ring. It’s not like someone is paying me to get this working. And even then… there are so many other things to learn that will be a lot more enjoyable to dig into.

If you don’t want to miss any of my future adventures: subscribe below and get every post delivered straight into your inbox.

Posted in Learning
Tags: , , , ,