Sunday, February 15, 2009
Well perhaps not all the way to Considered Harmful but Allen Holub is willing to call them Evil. I came across this article because I'm teaching OO Analysis and Design again this year and my students have generally already heard that the way you do encapsulation is you make all your attributes private and then add a public get and set method for every attribute. What's more, they generally feel if you change the type of the attribute then you need to change the return type of the get and the parameter type of the set. This of course gets you pretty much nowhere, and this is what Allen is railing against.
Now I am OK with Get methods as long as you swear you will never change the return type. The example I give the students is a bank account class with a balance. In the original design you keep the balance as a floating point number, 12.34000000 for 12 dollars and 34 cents. You add a GetBalance() method that returns a float, and Deposit() and Withdraw() methods that take (among other things) floats to represent the amount being deposited or withdrawn. Now when implementation time rolls along you discover that floating point arithmetic is expensive computationally, and needs lots of rounding to stay accurate: add 1.00 to 1.00, then add another 1.00 and the time may come when your number ends .01 or .99 ... neither of which banks care for tremendously. So you decide to store the balance as an integer number of pennies. Everything is OK in my book as long as you DO NOT CHANGE the signature of GetBalance(), nor of Deposit and Withdraw. These methods don't need to know what you just did. When Deposit tells you the amount is 50.00 dollars, your code can multiply by 100 to get 5,000 pennies, and add that to the balance. GetBalance() can divide by 100 (and round) to change pennies to dollars. That's a good use of a Getter method.
I am less OK with Set methods. I sure don't want a SetBalance() method. Deposit(), Withdraw(), and their cousins will change the balance. But there's no business rule in which it becomes necessary to announce that account 123456 now has $183.27 in it, and set the balance to that number. Having the method just encourages some code outside the class to do things that belong in the class - calculating service charges, or giving interest perhaps. Locking up access to the value means that if your business rules change, you don't need to look outside the bank account class for code that implements those business rules.
So do I think Get and Set methods are Evil? No, but I do think they should not be your first reflex, one of each per attribute. Make them earn their place.
Kate
Saturday, February 14, 2009
Here's another Channel 9 Video you need to watch: Rico Mariani: Visual Studio Today, Tomorrow and Beyond - Your Questions Answered. I love that in addition to planning for version 10 of Visual Studio, he's planning for 11, 12, and to a certain extent 13. To have the courage to start on a feature that won't really be done for ten years is very impressive. I'm looking forward to "Dev10" for a lot of reasons ... even more after watching this video.
Kate
Friday, February 13, 2009
You know the blog, now watch the Channel 9 video featuring Damien Watkins, Rick Molloy, and Don McCrady. I like this one because they talk about how they ended up changing their minds over the course of development, moving from a language-based approach to a libraries-based one. They get into why that's better and what C++ 0x features they needed to make it possible. A nice way to spend a little under an hour.
Kate
Thursday, February 12, 2009
Yochay has been very busy talking to Channel 9 and preparing Windows 7 material for developers. Here's a blog post from early January that lists some taskbar related videos you will want to watch. Screenshots of the taskbar really don't convince you of how much easier it is to use.
Still I can't keep from trying. Let me show you how I close things now. Imagine I have (among other things) a Notepad instance open on my machine. The "old way" to close it, if it doesn't have focus, is to right-click the icon on the taskbar and then choose close. You can still do that in Windows 7:
That's a right click, let go, move the mouse, left click. We know how to do that, and it's a ton less mouse moving than left click, wait while window paints, go on all the way up to the top right, click the red X. But I like this even better:
If I just move the mouse (no clicking) over the icon of one of the Notepad instances, they all show their thumbnails. One of them (the one I moused over) has a little red x showing in the thumbnail. Without clicking, if I move the mouse onto the thumbnail and pause a moment, I get the "peek" where that window appears (in case I can't tell from these tiny little thumbnails) and everything else goes transparent. If I click the little red x in the thumbnail, the instance closes. It's less clicks, it's noticeably faster and smoother.
These are the sorts of things that are making me so glad I put Windows 7 on the prime laptop. I would not go back!
Kate
Wednesday, February 11, 2009
Jennifer Marsman points out her favourite new Windows 7 feature - different default printers when you're on different networks. To bring up the dialog she shows in her blog post, bring up the Devices and Printers dialog (I do that by clicking Start and typing printer), then select a printer. That will give you a printer-related toolbar:
And yes "no network" counts as a network, so I can have the XPS writer as my default when I'm not on the network (if you've ever accidentally clicked a Print icon on a toolbar and then had to wait over a minute while the search for the printer timed out, you'll know why my default isn't really a printer at all) but I can have a useful default printer when I am on the network. Fantastic, and thanks Jennifer for telling us about it!
Kate
Tuesday, February 10, 2009
There's been a reasonable amount of blog talk about the removal of the "quick launch" area from the Windows 7 taskbar. What isn't coming across in the blogs I read is how there is an across-the-board attempt to make the taskbar more useful. Sure, making it easy to flip focus to a background window to see how it's doing is a good idea. But saving you from having to flip focus is a better idea, right? Take a look at this:
It's a piece of my taskbar, and the icon with the green on it is an Internet Explorer download dialog. That's a green overlay progress bar going across it. Here's another a few minutes later:
This is really, genuinely useful. And if you're thinking that getting your own applications to take advantage of this will require you to learn a bunch of API calls and the like - think again! If you have a progress bar control on screen, the overlaying in the taskbar will be done for you automatically on Windows 7. How's that for fun?
Kate
Monday, February 09, 2009
We all face times when we have a picture and we want the text. Maybe we have a printout we can scan, but we don't have one of those cool photocopiers that scans to a true text format like PDF or XPS. Maybe we took a screenshot during a web cast and don't want to retype all the code. That sort of thing. There used to be OCR in Word, but in Word 2007 it seems to have disappeared. No worries though, it resurfaced in One Note.
Here's a screenshot from a private web cast last summer (the actual content is in a recent Visual C++ team blog, so no worries about revealing super secret info):
Now, I open a new One Note document, paste this jpg into it, then right-click:
You can hit paste right in One Note if you like, but it tries to capture formatting etc. I pasted into Notepad and got this: Some samples structXfl; void meow(constX&)cout<<”meowconstX&):Copying.”<<endI;} void meow(X&&) cout << “meow(X&&): Moving.’ <<endl;} XfooOIreturn XO;} const X bar() return X(); } mt main() Xa; constXb; meow(a); I/Copying meow(b); I/Copying meow(fooO); ii Moving meow(barO); II Copying }
OK, it needs some spaces, and it's not too smart about {} or //, but it's quicker than typing it all yourself. And if you have a boatload of ordinary typed text (say a paragraph from a printed RFP that you want to quote in an email to various folks, or a powerpoint presentation) then it's even more accurate. And it's probably on your machine already!
Kate
Sunday, February 08, 2009
I had read that Windows 7 did the perf calculations differently than Vista, so I thought I would compare them. I took a picture of my settings as part of the whole "back up everything three different ways" process before the upgrade (me? burned before? ya think?) and here's what it said:
After the upgrade, it said:
So the same conclusion, but drawn from different numbers. Bottom line is I could mess around with this laptop and it would be faster, but it works for my day to day use. And things feel zippier on Windows 7. Sleeping and waking up, for sure. And finding the files I want ... but that's about jump lists and previews.
Kate
Saturday, February 07, 2009
Well, I did it. I put the Windows 7 beta on the laptop I use day in and day out. This machine had Vista on it, and the upgrade was utterly painless. All my software was still there and still working fine when the install was complete. The only glitch was that my built-in touchpad has become invisible in some way. This means I can't configure it to be less sensitive, which in turn means I was "clicking" a lot when I didn't mean to. I disabled it completely (using the 1980s-style UI of the edit-your-settings-on-boot experience) and other than having to carry a mouse with me when I take the laptop somewhere, there's been no other impact.
First impressions: I use jump lists a lot. Enough for a separate blog post. I like everything I noticed, except the default large-icons, no-text, group-everything setting on the taskbar. I fixed that:
(I've cropped it so it doesn't stretch the page)
I've said it before and I've said it again ... you can't really learn a product if you kick up a VPC once in a while but live your life in a different product. Windows 7 is stable enough to live in, and living in it will show what it's really like soon enough. I'm liking what I'm living.
Kate
© Copyright 2024 Kate Gregory
Theme design by Bryan Bell
newtelligence dasBlog 2.3.9074.18820 | Page rendered at Tuesday, November 05, 2024 2:19:12 AM (Eastern Standard Time, UTC-05:00)
|
On this page....
Pluralsight Free Trial
Search
Navigation
Categories
Blogroll
Sign In
|