My Software Notes

Useful things I discover

Archive for the ‘Uncategorized’ Category

To var or not to var. That is the question.

leave a comment »

You can always use or misuse or overuse Shakespeare to make a point.  Hopefully this is an example of “use” and not “misuse”.  🙂

Somewhere on this blog I posted about using “var” in C# (“var” is a pronoun).  In it I said you should only use it when it was obvious what the data type is.  Well, I’ve changed my mind.  What can I say?  Times change, people evolve, live with it.

I now use “var” all of the time.  I rarely, if ever, don’t use it.  If I am declaring a variable and setting it to null then I will explicitly name the data type, otherwise it’s “var”.

Why the change?  The first thing that led to it was some study of F#, which does implicit typing all the time.  Even if you don’t assign a value to a new variable the compiler will still figure out what the type is based on what you do with it later in your program.  Very nice.

(As an aside: Studying F# has made a big impression on how I code:  I tend to keep my variables immutable and declare another one if I am making a change – not 100% of the time as it would be impractical in my main languages (which, just now, are C#, TSQL and JavaScript), but probably 80 to 90%.  Another change caused by studying functional programming is that I am very aware of any side-effects my methods may cause and I try to write side-effect free methods and if they do cause side-effects I name them so it is clear that they do.  If you have only ever been exposed to OOP languages (like C#, Java, etc.) and procedural languages (like C, VB script, etc.)  I highly recommend studying a functional language.  It will expand your horizons.  In fact I recommend studying lots of different language types – more on that later.)

But back to the point.  So, studying a functional language that has implicit typing and seeing the advantages of that was the first reason.  The second reason was laziness.  The third and (for me) most important reason was that I really wasn’t gaining anything by explicitly naming the types.  Honest, in the years that I’ve been using “var” I have never had a problem figuring out a bug or how to modify some existing code because I used “var”.  So why would I not use it?  The fourth and final reason was that I can change the type of something and not need to change assignment statements. E.g., var myVar = SomeMethod(); If SomeMethod returns a bool and I change it to return a string – I don’t need to change that assignment statement.

If you need a deeper analysis of this then read Eric Lippert’s excellent article: Uses and misuses of implicit typing.  Or just start using “var” and see for yourself if it ever causes a problem.

Written by gsdwriter

April 21, 2011 at 8:46 am

Can’t open Windows Explorer from SharePoint

leave a comment »

A couple of weeks ago I made some changes to my computer to speed it up.  The usual stuff like fixing up the Registry, defragmenting the disks, etc.  The machine did speed up but not as much as I wanted.  

So, I went further and turned off some of the Win7 graphics features and turned off some services.

Turning off graphics features is not a big deal but the services … well you have to be careful with those, as I found out.

In the week following my tuning I noticed that I couldn’t open Windows Explorer from the “Action” menu of a SharePoint site.  Now what would that have to do with a local service?  

Turns out that the “WebClient” service is needed.  I turned it back on and the SharePoint “Open with Windows Explorer” menu item works again.

Who’d a thunk?

Written by gsdwriter

October 26, 2010 at 8:53 am

Posted in Uncategorized

Postback after disabling a button (ASP.NET)

with 2 comments

I’ve seen it on tons of sites.  You click the button, it becomes disabled and the page posts.  The disabling is so you don’t go clicking it multiple times while waiting for the server processing to complete.  

It’s all over the place, so it must be simple right?

Well, actually, once you find out how to do it, yes it is simple, but getting there?  What a pain.

I foolishly thought I could just add another even handler for the button click using jQuery. Nope.  Although jQuery adds the event handler rather than replacing existing event handlers, the action of disabling the button seems to kill the ASP.NET postback script.

Well, of course, I should be using the “OnClientClick” property of the asp:Button control.  No problem.  Nope.  That doesn’t work either.  It overwrites the ASP.NET postback script. 

This is ridiculous.  So it’s time to start asking Google.  The first few results tell me to add the ASP.NET postback script in server code and other real complex solutions.  These just seemed way too complex to me.  I have a rule of thumb that I follow at times like this: “If it’s getting more complex you’re going in the wrong direction.”

So I hunted some more and sure enough here is the simple answer: Disable a button control during postback.

Totally simple but what a pain to discover.

Written by gsdwriter

September 9, 2010 at 9:39 am

Posted in Uncategorized

I love jQuery

leave a comment »

JavaScript in a browser is a pain.  There is no getting around it.  It’s flaky, unreliable and its implementation varies from browser to browser.  

I am not a power JavaScript programmer, I use it when I need it on web pages, but I’m starting to need client scripting more and more, so I have to use JavaScript more and more.  Yuck!

I have a couple of books on it and I do GDD like most of us to quickly find out how to do something.  But I often find with JavaScript that a script doesn’t always work.

For example: stop the Enter key from submitting a form.  An apparently simple piece of JavaScript that you will find all over the web and yet the simple script I was using and that had worked for a year suddenly stopped working in Firefox.

I tweaked it and varied it and found other ways to do it and they all worked in IE and they all failed in Firefox.  With no explanation, no error message, no nothing.  It just silently failed.

I’d added that JavaScript to the site before I’d gotten familiar with jQuery and it was a really simple script for goodness sake, so I didn’t turn to jQuery immediately.  But after I’d torn out some of my precious hair I decided to dump plain old JavaScript and go with JQuery.  I added a link to one of the CDNs, spun up some simple jQuery and voila! It worked first time and in every browser I tested.

And then today I had to write something to make a set of checkboxes uncheck if the user checked the “None of the above” checkbox and uncheck the “None of the above” checkbox if they checked any of the others.  And it worked easily with minimal debugging (basically some typos on my part).

So, I will state unequivocally that jQuery rocks and I love it.

Written by gsdwriter

August 31, 2010 at 3:39 pm

Posted in Uncategorized

Microsoft Office is now Free

leave a comment »

Online versions of Microsoft Word, Excel, PowerPoint and OneNote are now available for free.  

Go to Windows Live and sign up.  You can use any email account you want, it doesn’t have to be Hotmail. Once you have signed up you will see a menu at the top of the page and one of the items is “Office”.  Click it and you go to the Office home page where you see a list of your recently edited docs and to the right you see “Create a new online document” with icons for Word, Excel, PowerPoint and OneNote.

So far I’ve tried out Word, Excel and OneNote.  They are limited versions of the full-blown desktop software, but they have all the basic features you use the most.

If you want a local copy of your work, you can click on the “File” tab and there is a download option.  (With OneNote you have to click “File > Properties” and then find the “Download” link on the menu on the Properties page. Why they did it that way is anyone’s guess.)

Usage is supported by advertising, so it’s not really free, but free enough I think.

You have 25 Gig of space for your docs, so you shouldn’t run out of room anytime soon.

So, now you can get started on that novel you’ve been meaning to write without spending a dime on a fancy new word processor.

Written by gsdwriter

June 11, 2010 at 10:53 am

Posted in Uncategorized

Changing your password while in a Remote Desktop session

with 30 comments

When your password is about to expire on a remote network which you access via remote desktop then how do you change your password?

Easy just press Ctrl-Alt-Del and the Windows Security screen (“Lock this computer/Switch User/ … /Change a password/…”) comes up.

Errr, well, actually, no it doesn’t.  The screen for your local computer comes up, not the screen on the remote computer.

So what now?  Do you just quietly sob?  Do you scream at the remote desktop machine and throw things at your monitor?

Never fear.  All is not lost.  Try “Ctrl-Alt-End” and, surprise, surprise, the screen you want on the remote machine appears and you can now change your pesky password.

For info on more keyboard shortcuts while in a Remote Desktop session:  Remote Desktop Tips and Tricks

Written by gsdwriter

February 9, 2010 at 10:01 am

Posted in Uncategorized

Synchronizing a domain password from a remote computer over VPN

with 2 comments

You’d think this would be simple because it’s something people have had to do for a long time.

My situation is this: I maintain an old system that is part VB6 and part .NET but the VB6 IDE does not run on Vista or Win7 (unless you have hardware virtualization and can use XP Mode), so I have a Windows XP virtual machine that I use.  It works great, but domain policy of the client requires a password change every 30 days.  This would be no big deal if I was in their office, but I’m not, so I had to figure out some way of synching up the domain credentials on the remote computer with those on the client’s network so that things like connecting up to the CVS repository (yes, they still use it) would work.

I Googled and Binged it but only found incomplete “solutions” or way complicated “solutions”.

The simplest solution was “lock the computer, then unlock and you’ll be asked for the new credentials” – didn’t work.  But after trying a couple of things I figured out something that did work and forced the “lock the computer” solution to work:  I mapped a network drive, using my new credentials and after a few seconds I got one of those XP balloon messages telling me that I needed to lock the computer and then log in with the new password. So I did and it worked.

So the real solution (at least on Windows XP) is:

Connect up to a network resource using the new credentials and after a few minutes Windows will ask you to lock your computer and log in using the new credentials.

I don’t remain connected to network resources on the VM, but maybe if I did, that would also force the synch.  If you remain connected to network resources then please tell me if that also works.

I hope that helps.

Written by gsdwriter

January 31, 2010 at 3:58 pm

Posted in Uncategorized