So you're copying your (common) code function into every application. right?
What the hell happened to code reuse!
What happens if your class name (If statically declared) or instance name
(Otherwise) is greater than 2 characters! Starts to look a little less
efficient.
You say "my app has 300 forms etc etc". Nothing is wrong in having common
display in the app. In fact this would be a valid reason to do this kind of
thing -this is not what this thread was about ... "I got so sick of the long
winded messagebox syntax in C#". Also is VB syntax that much better cos it
uses MsgBox, even that needs same params to get the same desired display.
You also mention that "it makes the code more readable". Well to you it
might, but what happens if Joe Programmer decides to rewrite his own version
of a for loop (and use it throughout his code) cos he don't like the syntax
or Jane Developer does the same with a DataAdapter because she wants to use
the word Copy instead of Fill (and like Joe uses it thoroughout her
programs).
But wait. Thats not all they do. They have re-written all sorts of other
constructs too and used them extensively thoughout their code.
Now this is my personal opinion (and we both obviously disagree), *but* I
would just hate to have to pick up Joe's and Jane's code. Since they copy
the code of all their custom bits into each application, it has not only
caused additional Bloat but has caused inconsistancies in code since from
time to time they change the code of their custom methods.
Just a final thing, you say at the bottom "this leads to lots of repeat
code". Well I find this quite amusing I must admit. MessageBox has 12
overloads and I believe the maximum amount of parameters used in any one
overload is 6 (yes thats right SIX . That isn't causing repeat code).
My point is that if you have had to write some code to save your pinkies
from RSI for MessageBox then there is plenty of more deserving things in the
Framework that requires your alterations!
"Michael C" <mc*****@NOSPAMoptushome.com.au> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
"Mark Broadbent" <no****@nospam.com> wrote in message
news:ex**************@TK2MSFTNGP09.phx.gbl... Hahaha. Nice one!
So we have ...
Normal = MessageBox.Show(...)
= 15 char
Your = X + Y
where
X = chars needed to declare instance of your class OR chars of class -if
your method is static
Y = your function name
(oh and don't forget add a reference to your dll!)
You're making a huge stretch here. For a start the class is already
declared with other common function in it (obviously you have such a
class, right?). The class is not in a dll and it is only declared once
anyway.
Have a look at these couple of examples to see the big difference
MessageBox.Show("Text", "Caption", MessageBoxButtons.OK,
MessageBoxIcon.Information);
becomes
GT.MsgBox("Text")
if(MessageBox.Show("Save Changes?", "Caption",
MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question,
MessageBoxDefaultButton.Button1) == DialogResult.Yes)
becomes
if(GT.MsgBoxSaveChanges() == DialogResult.Yes)
I bet yours is bigger than the normal syntax. MessageBox.Show is
overloaded so those extra params are not necessary.
Actually they are. You really need to have an icon on the messagebox so
you have to have at least the first 4 params.
I know where you are coming from though, especially if you are using
particular default parameters for the same look and feel of your
messagebox, but reinventing the wheel JUST to save some typing is in this
instance a very bad idea.
Total rubbish. How can this be a very bad idea? What possible side effects
could there be?
If you took this to it's logical conclusion you would be eventually doing
this for nearly everything in the framework.
Not really. If you think about it there are only a few places where you'd
use this sort of thing, the other one I use it for is adding params to a
command object.
I can think of a couple of reasons to do this kind of thing, but saving
typing aint one of them.
I don't see anything wrong with saving typing, although it also makes the
code more readable and reduces repeat code. If the caption of the
MessageBox is the same throughout the app why should I specify it in
hundreds of locations. (My app has 300 forms each of which would show at
*least* one messagebox).
What I would do instead is create a simple VS macro OR use one of the
productivity editor add-ins to VS so that you could (at the press of a
couple of keys) insert the base code of your messagebox statement.>
This sort of thing leads to lots of repeat code.
Michael