|
I suppose a write-only property (in whatever language, but preferably C#) could be used when defining something like a queue (Enqueue) or a stack (Push). (Though not recommended.)
|
|
|
|
|
I quite often use write only properties in C#
Consider this:
Object A depends on an internal state and also needs an Object B for whatever it does. Object B inherits from a baseclass or interface, so there are many classes that may be used to create an instance to use as object B. Hardcoding it in A is not an option. Instead I use a write only property of A to pass a suitable object B at runtime. Object A then reinitializes it's internal state and prepares B for its use.
I do not want to have access to object B anymore. It is not needed and indeed any tampering with B would have a bearing on A's state. With a write only property this problem cannot arise.
|
|
|
|
|
Is there a reason for this appearing all over the code???
try
{
if (something is wrong)
throw new exceptionaboutwhateveriswring();
...
...
...
continue work
}
catch (whatever exception was just thrown)
{
Console.WriteLine(information about the error);
}
|
|
|
|
|
Hi,
that is a very clever piece of code. The normal approach:
if (!something_is_wrong) {
} else {
}
has several shortcomings:
1. the tests use negative statements, so they are error prone.
2. the error messages do not include class names and line numbers automatically
3. problems don't get encapsulated in objects
4. it disregards the exception trapping functionality available in Visual Studio
So basically it is old style, and against all modern OO principles.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Would this be better?
if (somethingIsWrong)
{
}
if (somethingElseIsWrong)
{
}
Because I don't see the point of throwing a exception only to catch it in the same place.
1: No more negative statements
2: The errors would be something that doesn't deserve exceptions like incorrect input (IIRC)
3: This shouldn't be a problem
4: Don't know
|
|
|
|
|
I'm afraid you've missed the joke icon.
The coding horrors forum was the right place to put it.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
I haven't been here long enough to recognize all these icons...
|
|
|
|
|
No problem. You'll catch on soon enough.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
"You'll catch on soon enough"
.
|
|
|
|
|
|
This is a function of mine, could I get a critique on this? The reason for it being there is because exceptions coming out of the lower level library were not very descriptive or helpful to the guy trying to understand where the config was screwed so this layer was added to get some extra info into the exceptions that were coming up if files were missing and so on.
Public Shared Function GetInt(ByVal iniFile As String, ByVal sectionName As String, ByVal keyName As String) As Integer
Dim i As Integer
Dim ConfigFile As IniConfigSource
Dim ConfigSection As IConfig
Try
'check file exists
If (Not System.IO.File.Exists(iniFile)) Then
Throw New Exception("Config file does not exist: " & iniFile)
End If
'Access the file
ConfigFile = New IniConfigSource(iniFile)
'Get section
ConfigSection = ConfigFile.Configs(sectionName)
'check section exists
If (IsNothing(ConfigSection)) Then
Throw New Exception("Config section does not exist: " & iniFile & vbTab & sectionName)
End If
'get key and check it is a valid value
Try
i = ConfigSection.GetInt(keyName)
Catch ex As Exception
Throw New Exception("Exception attempting to access integer key: " & iniFile & vbTab & sectionName & vbTab & keyName)
End Try
Return i
Catch ex As Exception
'Exceptions come in here
Throw ex
End Try
End Function
|
|
|
|
|
Sure does.
Yeah, that's bad; catching your own exception is like laughing at your own joke. Or other behaviours less kid sister friendly.
|
|
|
|
|
Probably written by a VB'r. I have seen that pattern used abundantly.
|
|
|
|
|
Only because C# doesn't support On Error Resume Next
You know, every time I tried to win a bar-bet about being able to count to 1000 using my fingers I always get punched out when I reach 4....
-- El Corazon
|
|
|
|
|
dan neely wrote: Only because C# doesn't support On Error Resume Next
Thankfully.
Steve
|
|
|
|
|
No, that would be
try
{
}
catch
{
}
|
|
|
|
|
PIEBALDconsult wrote: // Ignore Exception
Oops, I think you meant, return null .
|
|
|
|
|
Nah, actually I should have had several instances of that construct, but I didn't want to take up much space
try { statement } catch{}
try { statement } catch{}
try { statement } catch{}
try { statement } catch{}
...
|
|
|
|
|
never heard about this?
|
|
|
|
|
Today, some headhunter for a firm in Singapore asked me if I wanted to apply for some C# developer position that called for at least five years of experience. The initial email went something like this:
Hi,
Good morning this is ----- of [company removed], we are currently looking for an IT Professionals who is open for the opportunity to work in Singapore for permanent posting and your friend 'J' had forwarded me your resume but it looks like its only a summary, can you email me again a detailed resume of yours? Also attached is a reference form, kindly fill it up and email it also to me coz I need to attach it to your resume before forwarding to my supervisor.
Thank you and hope to hear from you soon.
[Edit: The copy of the resume I sent her was *three* pages long and it listed every programmer job I had since 1999, in addition to the all the open source projects that I worked on, the articles I had done for CodeProject, and the certifications and awards that I had. Despite that, she still called it a "summary"]
To make things worse, she couldn't even properly remember (or even spell) J's full name. The attachment she mentioned wasn't even attached to the email she sent me, and it was all downhill from there. Here was my initial reply:
Hi -------,
Sorry, I'm not currently interested in working in Singapore, but you can give J [edit: I corrected the spelling for his name] my thanks for referring me.
At first, things were cordial. Her response was the typical head hunter speak that we've all come to know:
Hi,
Thank you for your reply. If Im may ask do you know any friend or colleague who have the same qualification as yours, or who is JAVA, C#, ORACLE DBA or whose experience using a ACTUATE REPORT, kindly email their names and contact # to me so I can call and talk to them.
Your help is highly apreciated.
-----[Name deleted]----
The bad English was starting to get on my nerves. I don't know what got in to me, but I had to reply:
Me:Nope, sorry. There's not very many programmers here in ------ with more than eight years of experience like myself.
Now, out of curiosity, what made you think my resume was a 'summary'?
She didn't answer my second question. Instead, all I got was a simple "Thanx". Maybe my own judgment got the best of me, but the combination of the LOLCode speak and the fact that she just insulted my life's work experience made me snap.
Me: You're welcome. Maybe when you learn how to properly spell and type in English, you'll actually find more qualified applicants who will take you seriously and won't turn you down. Have a nice day.
...and it just gets worse from there. Her reply:
Recruiter: Sorry, its only a typo error. But anyway I hope also that next time you won't be too ARROGANT. And for your info your not few, there is lot of programmers here in -----, thier just hiding. And one more thing your not also qualified coz your a jumper................
[Note: I later found out that this same company was looking for three senior-level C# developers and they couldn't find anyone to fill those positions because the qualified developers were 'hiding'. So much for finding replacements!]
She clearly couldn't tell the difference between an arrogant person, and an angry potential hire. From her perspective, she was still clueless about why I became so...hostile. She was starting to take it way too personally. Nevertheless, I was still annoyed at how clueless she was about what she just did:
Me: Then you still wouldn't be wasting your time on me if there weren't a few of us now, would you?
And remember, its "their", not thier. It's "because", not "coz". There you go with your English again. Now run a long, little "associate" consultant, before you get yourself into trouble for your "charming" recruiting skills.
Most recruiters would probably forget about replying at this point, considering that the potential hire (me) didn't seem interested, nor was the conversation getting any more productive. Now here's the "award-winning" reply that I didn't think would happen:
Thank you for your correction. Anyway, one question, Are you gay? You sounds like you belong to them, Am I right? Can you be my consultant? MR. GENIUS???????????????
After some googling, I managed to get her company's address from within the country, as well as their head office in Australia. Here's the last reply:
------,
Let's back up a bit, shall we? Before all of this mess escalated, you inadvertently insulted my friend by not being able to spell his name properly, and more importantly, you even insulted me by calling my three-page resume of my life's work a "summary". At least do some research on what all those "fancy" keywords mean in my resume before you go asking for a summary because you can't seem to understand it all means. I turned down this offer to apply for work in Singapore precisely because you didn't even take the time to ASK a professional if my resume was actually qualified, or just a "summary". If that's a "summary", then I dare you to find an experienced programmer who will tell you otherwise.
Maybe when you start acting like an adult, you'll actually get people with more than five years of experience to listen to you.
So no, I'm not gay, and no, I won't be your English consultant. I'm a programmer, not a linguist, and you are way out of line.
And just in case the words I just typed above are 'too big' for you to understand, I've forwarded a copy of this email to both the head office in Sydney, Australia and the one in Makati so your superiors can do all the translating for you.
So that's pretty much it for this little story in progress. In hindsight, it probably would have been easier just to say "no", but there's just something so innately offensive about this whole incident that I just can't put my finger on...
|
|
|
|
|
Interesting story, but shouldn't it be in the lounge for all to pour scorn on said recruiter? Coz I iz no' interested in your summary[sic]. At least she didn't say "Itz Urgnt. Plz email me codez."
|
|
|
|
|
Pete O'Hanlon wrote: At least she didn't say "Itz Urgnt. Plz email me codez."
Wow, that made my day.
Edit of Edit: It was moved.
modified on Friday, April 4, 2008 2:42 PM
|
|
|
|
|
Pete O'Hanlon wrote: Interesting story, but shouldn't it be in the lounge for all to pour scorn on said recruiter? Coz I iz no' interested in your summary[sic]. At least she didn't say "Itz Urgnt. Plz email me codez."
Good point, and so noted.
|
|
|
|
|
Just curious, what's her race?
Jumper is everywhere in Singapore, we call it job hopper here. They are everywhere here because one reason: the companies are not bothered that they are job hop and still hire them. By the way, it's the way to do if you want your salary increase faster than GST.
Some job agents here, yeah, they aren't professional at any level, at all. Some of them, when they got a position, just goes to their company's database and mass mail to everyone, without even look at your resume.
|
|
|
|
|
darkelv wrote: Just curious, what's her race?
Jumper is everywhere in Singapore, we call it job hopper here. They are everywhere here because one reason: the companies are not bothered that they are job hop and still hire them. By the way, it's the way to do if you want your salary increase faster than GST.
Some job agents here, yeah, they aren't professional at any level, at all. Some of them, when they got a position, just goes to their company's database and mass mail to everyone, without even look at your resume.
This particular recruiter is a Filipino by blood, much like myself (except that I'm heavily Americanized). Btw, What's GST? And what's it like living in Singapore? Are they really that strict? And how's the competition in the developer job market?
|
|
|
|
|