Being a developer or just a good Googler

Scott Hanselman posted a quick blog post about a question he got from a young developer asking “am I a developer or just a good Googler?”  I thought it would be fitting to post it here in my neglected blog.

It’s true that we find ourselves trying to Google an answer often.  In fact, my Google history is up to about 60,000 searches over a few years.  I think Scott has a couple of great points in how to better yourself as a developer.  I try to do project Euler on occasion and I also read as much as time will allow.

I would like to add one more suggestion though:  learn test driven development. I started to do this a couple of weeks ago, and it has really changed how I program.  Test driven development forces development to be more focused on specific problems and solutions to those problems by starting with a failed test. You then program until the test is successful.  Then you rinse and repeat.

It helps you become a better programmer because once you’ve learned how the tests work, there’s really nothing to Google; it’s just you and the specifics of the test.

The internet is a fantastic tool for helping developers do their job faster, but it does allow us to become more complacent. Learning how to actually develop instead of just “Googling” is the difference between good and great developers.

TrueIfAll and TrueIfAny Functions for Javascript Arrays

I’m primarily a .NET programmer and therefore, I’ve become very familiar with LINQ.  I recently needed a trueIfAny function on a few javascript arrays, much like the All<> and Any<> functions in LINQ.   I am aware of LINQ to Javascript which does implement those functions, but I just needed something simple.

Fortunately, it’s very easy to extend functionality of objects thanks to prototype.  Here is the code I wrote to accomplish the task of creating a trueIfAll and trueIfAny function:

if (Array.prototype.trueIfAny == null) {
    Array.prototype.trueIfAny = function (conditionCheck) {
        for (var i = 0; i < this.length; i++) {
            if (conditionCheck(this[i])) {
                return true;
            }
        }
        return false;
    }
}

if (Array.prototype.trueIfAll == null) {
    Array.prototype.trueIfAll = function (conditionCheck) {
        for (var i = 0; i < this.length; i++) {
            if (!conditionCheck(this[i])) {
                return false;
            }
        }
        return true;
    }
}

And to use it:

if(myArr.trueIfAny(function(ele) { return ele.Toggle; }))
{
//Run if any records are true
}

if(myArr.trueIfAll(function(ele) { return ele.Toggle; }))
{
//Run if all records are true
}

The trueIfAll and trueIfAny functions iterate through the array, calling the passed in function (conditionCheck) each time. The passed in function accepts one parameter and needs to return boolean. The parameter is the element produced by the iteration.

In the case of trueIfAll, if the passed in function ever returns false, trueIfAll will return false. In the case of trueIfAny, if the passed in function ever returns true even once, trueIfAny returns true.

Hope this helps someone!

Programmers learning something new: a simple guide

I struggle a lot to learn new programming languages on my own.  It’s not that I’m not smart (I want to believe I am VERY smart) but it’s the combination of lack of time, lack of desire and having no answer to the question: “Great, I’ve learned X… now what?”

I’ve started to learn about Django, and I believe it will be DIFFERENT this time.  Why?  Because I have created a simple guide to learning something new from a programming perspective:

STEP 1: Accept that you may burn out and ask “why bother” and figure out the answer to it before starting

I had stated before:  It’s hard for me to learn something new when I expect to do precisely nothing with it.  This is what happened with me and Ruby on Rails.  Ruby is a cool language and Ruby on Rails was really awesome to build scaffolding with.  However, I didn’t really know what else I wanted to do with it.  I suppose I could have learned it’s cool AJAX capabilities that go with it, but really, it just didn’t appeal to me.  Therefore, it went on the infinite back-burner

Back when LINQ was new, I struggled to learn it as well, because even though I do .NET professionally, I was so knee-deep into what I was doing that it would have been almost a waste of time to really sufficiently learn it.  I finally got a project in which allowed me to utilize LINQ to SQL effectively and easily and since then I wouldn’t know what I’d do without it. Again, once purpose settled in, I was ready and very willing to learn.

Your ‘why bother’ may be different.  Your success may be dependent on how you handle it.

STEP 2: Do the tutorials

These days, it’s pretty hard to find popular frameworks which have no or incomplete tutorials (I’m sure anyone could find examples where this isn’t true, but in general, it’s true).  Also, framework creators know that a quick and simple tutorial is the best chance for a developer to get on board, especially in the framework’s early stages.  Django has a wonderful tutorial, split up into four parts building a poll system (I feel like poll systems are the hello world of the web development world).

Here are reasons why I don’t like to just “dive into the code”:

  • You cannot be guaranteed what you are looking at is the correct way to do it
  • Most of us are lazy, and there may be certain things hidden by shortcuts which obfuscate key basic techniques used by the framework/programming language
  • There is more impact in doing it yourself, seeing what works and what doesn’t, rather than just reading through it and trusting it works
  • It’s less fun!

Tutorials are the best way to get yourself acclimated, set up your environment, and ultimately help you decide “why bother?”

STEP 3: Research technology on StackOverflow

I am a HUGE fan of StackOverflow.  I’ve never met a bigger group of developers, all willing to write great questions and thorough yet quick responses.  The reputation system is awesome.  Any developer not utilizing StackOverflow is SERIOUSLY missing out.

StackOverflow is a great way to see what difficulties most users have, as well as to see how these user’s issues are resolved.  While it’s not immediately helpful, you will drill back into your head, and all of a sudden, you’ll come up to a problem where you say “wow, I remember this on StackOverflow!”

StackOverflow is a great place to see how a technology stacks (get it) up.  For example, a quick search of Django immediately show questions about scalability, whether a user should use Django or X and configuration questions. A few quick searches and research will give you a sense of what type of framework Django is.

STEP 4: Think Small

I picked Django because I had an idea for a website and needed a specific framework.  I discussed the idea with a buddy of mine, a developer who uses Django, and he sold me the benefits of using Django.  I owned hosting which could support Django but not .NET, so it looked like a good choice.  Also, I was in the ‘market’ to learn something new.

Unfortunately, I couldn’t just dive in because I needed to learn Python as well as the basics of the framework.  Therefore, I decided to table the original idea for now and decided to build a personal website for myself entirely in Django.  It took hours to do, I had to read up on a lot of how Django and Pyhton works, but the idea was simple enough to wrap my head around so I was successful.  You should see a site hopefully by the end of next week.  Because it’s my own personal website (and not a large, professional site), it’s okay if it has a few problems with it or if I did it incorrectly;  it’s all part of the learning process.

STEP 5: Have a buddy help you learn

It’s nice to be able to send code to someone, even if it is just a file or two, for them to kindly message you back and say “get out of your .NET world, here’s a better way to handle what you are trying to do.”  Having a human allows you to do a sanity check as well as to see if you’ve missed any nuances.  It’s also nice to have someone to ask for help on really simple yet bothersome problems.  It’s a lot harder to do this using the Internet.

STEP 6: Have fun!

Every blog post with steps needs a cop-out answer.  Here is mine.  Most of us are learning new languages because ultimately we want to.  You should have fun with your learning experience!

Mini Post – DotNetNuke and web.config problems

I could have Twittered this but I wanted to put it here: Every now and again I find myself refreshing my developer’s copy of my project on my local computer from source control.

The way I have source control is primitive and probably incorrect. I tend to save ALL of my project (DotNetNuke included) into source control, so when I get a clean setup, I can basically run it out of the box.

This particular time, I was working with a different database than I normally do. Because of this, my source control wrote over my web.config and copied the wrong database settings, which resulted in the web.config pointing to a no-longer existing database.

When I loaded up my website, I was greeted with the installation wizard from DotNetNuke. “Okay,” I thought, “Perhaps I forgot to update this particular database with the new DNN version.” I clicked on next a few times and realized it was just the wrong database being referenced. I changed the web.config to be the correct database and credentials and all was well…

Or was it?

I loaded up my project and I was getting rather unhelpful “I need to put a ScriptManager on the page in order to use AJAX.net” error. I just couldn’t figure it out! It worked before! Long story short, the DNN install wizard messed around with the web.config and broke a few things configured specifically to my install. Once I pulled up an older web.config, everything worked perfectly.

This wasted about 2 hours of my time (which I don’t really have) and was easily avoidable if I was paying attention.

Lesson learned: Always be methodical with processes which you perform regularly.  If something strange goes wrong within the process, it probably doesn’t belong and should be approached very, VERY carefully.

DotNetNuke Settings Issue: Truncated Data

DotNetNuke is great.  It has a great established core, along with a fairly straight forward process for developing extended modules.  You can use the already established DotNetNuke settings framework in order to facilitate settings for each instance of your own module.

We have a unique install in which we have central data that is shared by many custom modules.  I needed a way to have specific settings per portal, so I built a custom settings library.  I also wanted to be able to override these settings so I built in an XML parser to do so.

I found out the hard way that the settings table has an nvarchar size of 2000.  This almost never affected us, since the XML is generally smaller than 2000 characters, but I had one setting that went over.  It messed up my xml, and broke my module.

My immediate fix was to change the core database.  I made the settings to be nvarchar(MAX), and set up the add and update stored procedures to accomodate them.

I believe the best way to fix the issue without changing the core is to create another table, which either has a text type or a varchar(MAX) as the value.

Visible=”false” vs. display:none;

I find that when you are a new programmer or a programmer using a technology for the first time, there are a few gotchas’ that could make or break your learning experience.  When learning the power of .NET, especially after developing primarily in PHP,  the differences between Visible=”false” and display:none; was a huge gotcha for me.   I figured I’d help you realize what exactly the differences are and when you should use one or the other.  Take the source code:

<asp:Panel style="display:none;">
Error Message
</asp:Panel>

and

<asp:Panel Visible="false">
Error Message
</asp:Panel>

If you were to render both of these, you would see the screen the same thing: nothing.  However, if you look at the source of both of them, you will realize that the former will appear in the source but the latter will not.  That’s because in the first example, command display:none is CSS, which is client-side and in the second example, “Visible” is a server-side. On more complex pages, they are very much different.

When to use the display:none;

Let’s say you have a form in which you want to hide some elements of it, entirely for user experience (perhaps you want to hide the address field in case it is optional). If you used Visible = false, the button would have to postback, run back-end code to change the visible=”true” and render back to the browser the entire page. This exercise taxes the server, and is not an optimal user experience. It would be nicer to open the box via javascript.  if you used style:none; on an element, you would just need to run display:block; in order to show it.

When to use Visible=”false”

If you will never need access to the element via Javascript, then this is the better function to use.  This way, the element will never get rendered, and therefore keep the precious bandwidth of your pages to a minimum.  Also, maybe you want to run server-side code when you restore the address field. In this case, it is better to use Visible=”false”

I hope this helps you better understand the differences between the two types of hiding elements in .NET.  If you have any questions, let me know!

ModalPopupExtender .Show() Caveat

I’ll admit it… I don’t mind AJAX.NET.  In fact, I like a lot of the toolkit controls they provide.  Because I am “chained” to .NET and DotNetNuke, I don’t much of a choice when it comes to bleeding-edge technology.

One thing I tend to use frequently is the ModalPopupExtender.  I had a requirement to show the modal popup when the page loads.  Easy enough, I just instansiate the code and in the onLoad code-behind do mpe.Show().

However, this didn’t work It gave me an ugly error.  After sifting through a bunch of unhelpful forum posts online, I came across this issue in the AJAX Control Toolkit issue tracker.  Reading through the description, you notice that the problem has to do with the fact that there is a missing semi-colon if you try to invoke the modal through server-side on a page with validation.

Because the modal I was programming would not need the validation on the page, I simply turned off validation when the modal was invoked.  This worked like a charm.  If you require validation with the modal, I strongly suggest you check out the issue tracker page.