Shorthand Properties = Lazy Programming, IMHO

During an in-class demo of some code I had to edit (and that was inherited from a couple classmates), I mentioned that I really disliked some of the code my classmates had written. Namely, I didn't like their use of shorthand properties. C# lets you do something like this:

 
public type Name{ get; set; }
 

I don't like that. To me, it violates the encapsulation aspect of object-oriented programming. Encapsulation (in a nutshell) means you "hide" the attributes of your class, and limit the access of external code to those specific accessors you create. In C#, we can easily encapsulate by making our member variables private and then create public properties.

Now, with shorthand property syntax, you can skip creating member variables. The property itself becomes the member variable.

Let me repeat what I said earlier: I DON'T LIKE THAT.

So one of the guys I inherited this code from asked my why I don't like that syntax. I explained my idea of encapsulation (pretty much verbatium of what I wrote above) and also made a few more points.

My biggest beef with shorthand properties is that you can't perform any validation on the input value. The only guarantee you have is that the data is type-compatible (since otherwise the compiler will not build).

I much prefer standard syntax, which lets you do something like this:

        private int? majorID;
 
        public int? MajorID
        {
            get { return majorID; }
            set
            {
                if (value.HasValue)
                {
                    if (value > 0)
                    {
                        majorID = value;
                    }
                    else
                    {
                        throw (new Exception("'Major ID' must be greater than zero."));
                    }
                }
                else
                {
                    throw (new Exception("'Major ID' must contain a value."));
                }
            }
        }

As you can see, I can do a little bit of error handing very easily with standard syntax. To me, that is more than worth the small amount of extra typing involved.

What do you think? Let me know...

:]

Comments (0)

There are no comments for this entry.

W3Schools is teh awesomeness

It is either really sad, or really stupid (and maybe both) that I spent most of one afternoon Googling like crazy to try and find a good partial-page-refresh script example, and the place I wound up actually finding the most useful tutorial was the last place I thought to look: w3schools.com

I've benefited greatly from the HTML and CSS tutorials W3Schools has, but for some odd reason it never crossed my mind that they might just have what I needed. I had even remarked to someone else that they also had AJAX tutorials, but it never crossed my mind to check there first.

D'oh.

Anyway, I did find a damn fine tutorial, and it even included working code! All I had to do was change a few values in the JavaScript file, point it at a PHP script I had built, and viola! Partial-page-refresh! Wooooo.

The best part is that this script seems to work on every major browser (except, of course, IE6 and lower) [EDIT:] It seems a png fix script I was trying out was what was keeping the partial-page-refresh from working. It does actually work on IE6 [/EDIT], and (even better!) behaves almost identically in every browser I can test.

Those that are curious can visit my portfolio site to see my implementation, and visit the source page to see what the original looked like.

Cheers!

Comments (0)

There are no comments for this entry.

falcon1986 is my hero...

I've been looking for ways to make this site more responsive (especially the aggregate pages, like Articles, Tutorials, etc.). Some of these pages can get pretty long, so anything that would optimize how they get from me to you is most welcome.

So I stumbled onto a page from the Yahoo! development team where they talk about compressing pages to save bandwidth. "Gee," thinks I, "that would probably help out a lot." So I go a-googling to see how hard it is to enable any sort of compression on a dynamic website.

Aaaaannnnd... I find lots of links to people complaining about how my host and others like it disable the compression functions on their Apache modules, since it's so CPU intensive.

"Poop!" says I. "There goes that idea..." (sadface).

Then I see this article. Hmm. Innntereeesting. Maybe this will work....

And it did! I modified the code I found there a bit to match what I am already using, uploaded my modified php.ini and .htaccess files, and, viola!, the site takes off!

We're talking compression ratios of over 75 percent, people. 75 percent!!! That means you dial-up users don't have to twiddle your thumbs (as much), and everyone else is getting a page that has an almost audible snap! as it loads...

So I'm very happy right about now.

:]

Comments (0)

There are no comments for this entry.

Rolling, rolling, rolling...

...Keep them blogs a'rolling, BLOGROLL!

Heh. Yeah, I'm a dork. What do you want? Shakespeare? NOT.

Anyway. What's been on MY mind lately is "how does one make an effective blogroll?" I had ideas, but I wanted to see how the rest of the blogosphere does it first. So, of course I fired up Google, thinking I should find some good articles relatively easily....

NOPE.

You would think something that is so common to so many web sites would have some pretty good resources. And, let's be fair, if you're using a "commercial" CMS package like Wordpress, Joomla!, or Drupal (to name a few), you are in luck. If, like me, you are writing your own CMS, it's not so nice. I only found one decent tutorial. Fortunately, it does prove the old adage that "quality" beats "quantity" every time, since it's a darn good tutorial.

So, look for the GNS blogroll to change sometime soon, once I've worked the bugs out of the new script. I think you'll like it.

:]

Comments (0)

There are no comments for this entry.

Survey of Programming Languages I

I'm currently taking a course that is called "Programming Language Pragmatics" but could just as easily have been called "Survey of Programming Languages," or something similar. We're basically discussing various programming languages, and then writing simple programs as a method of learning the idiosyncrasies of how different languages are implemented. So far, we've done COBOL, Ruby, Python, and F#. Since I have a penchant for being outspoken, I thought this would be a good time to rant discuss my opinion(s) so far.

COBOL

I can only say this: Thank you, ANSI. Learning your language left me feeling like my I.Q. just dropped at least 10 points...

Ruby

I can sum up my feelings about Ruby in one word: Meh. Honestly. What is all the fuss about Ruby coming from? I can only guess that it's a Rails thing. I didn't do a Ruby-on-Rails application. I wrote a simple Ruby console app. And it was BORING. And irritating. Man, do I hate that coding style...

Python

I haven't actually written my Python project yet, but I did have the misfortune of having to become a little bit familiar with it a few months ago. If you want to know how I feel about Python, you'll have to IM me, because what I would say is unprintable here. I can sum up my feelings about Python in one word, though: ugh. Why does anyone think that a white-space aware language that uses indents to define code blocks is a good thing? HUH? Bleh...

F#

Holy crap. That's all I can say. F# broke my brain. I cannot code in functional programming languages. It's not a matter of "I don't want to." It is a matter of "Ow, ow, oh, please make the bad man go away." I have never been so frustrated in my life, and that's saying something...

So there you have it. So far, none of these pretenders can even hold a candle to my beloved C#.

:]

Comments (0)

There are no comments for this entry.

Page: 12345PrevNext

Invalid login. Please try again...

Forgot password? Sign up