|
That depends a lot on your language. Its a common (and safe) technique in C++ using RAII techniques.
|
|
|
|
|
This is Java code.
Returning a value "null" is not the best idea, but it's a invalid value one can identify as such.
I actually often return values in that way:
switch(key){
case x: return a;
case y: return b;
default: return null;
}
It's pretty handsome and easy to maintain.
regards
Torsten
I never finish anyth...
|
|
|
|
|
Since the Nullable<> thing was introduced, it seems that MS encourages developers to use null as a "special" and possibly meaningful value.
Personally I don't have a strong opinion on that, but often after I declared sth as T? I had to change it to T due to interopability issues and too many not-null checks.
Greetings - Jacek
|
|
|
|
|
If you're going to say something is bad, could you at least explain to rookie doofuses like me why it's bad?
Due to my lack of experience, I look at your code and I have no idea what the problem is. Furthermore, none of the comments here helps. Explain to me like I'm a complete idiot (which I occasionally am).
|
|
|
|
|
Seems to me what they're talking about is the use of null as a return value. "They" don't seem to like it.
Seems to me there's lots of "personal preferences" in a lot of threads found on this forum. To me, returning null is just fine; as an old database guy, null proves to be a very handy and very real data type/value.
|
|
|
|
|
As to the return thing...
Camp 1 says, when writing a method/function, you should have one entry point and one exit point. For languages that use return to exit the method, this implies a single return at the end of the method/function. Using this model sometimes involves multiple nested if statements.
Camp 2 might say I like to validate all preconditions and immediately return if something appears amiss, but then I have one return at the bottom for the real answer.
Camp 3 might say, I use assert() for things like Camp 2 does with returns, but I still have one return at the bottom.
Camp 4 might say, just throw a return in wherever it makes sense.
Camp X, might pick and choose what they want from other camps.
|
|
|
|
|
|
There is a dialog opened - a password-dialog.
When it returns OK (dialog is confirmed / left with "OK" button) the app not uses the entered password, but refers to some preference stored before.
Passwords which are entered by the user in a customers application, may never be written to files - no matter if ASCII, binary or whatever. It took me a couple of hours to verify that no password is stored in that application and no password is read at any time. A password must always be kept in the RAM and disposed when the application is shut down.
Also the stored password in the database should be encrypted.
regards
Torsten
I never finish anyth...
|
|
|
|
|
Wow, from looking at that piece of code, I'd never know anything was awry. Without me looking up a bunch of APIs, I'd never have a clue it was doing any of that wrong.
|
|
|
|
|
If you're really worried about security, don't forget to overwrite that password in RAM immediately when you're done with it.
Wouldn't want that cleartext password to get paged to disk.
patbob
|
|
|
|
|
You'd have to physically find it first.
|
|
|
|
|
I have only just found out what this would do:
That line was causing one of our webpages to load extremely slow, and I wasn't sure why. It seems a control placed inside of an HTML comment in an ASP.NET page will actually be executed (the control was in development and was very slow). So the HTML that gets output based on the above code might be:
<!--
Using a server-side comment, on the other hand, does not cause this problem:
<%----%>
That will not render to any HTML (as expected). I suppose it makes sense, but still had me stumped for a bit.
|
|
|
|
|
I'm not sure that's Hall of Shame worthy, seems like quite an understandable mistake to me! (Particularly as the 'commented out' code probably shows in green in your IDE ...)
|
|
|
|
|
BobJanova wrote: I'm not sure that's Hall of Shame worthy, seems like quite an understandable mistake to me! (Particularly as the 'commented out' code probably shows in green in your IDE ...)
I agree. In addition, this can be a good post to the Tip/Trick section.
Good judgment comes from experience, and experience comes from bad judgment. Barry LePatner
|
|
|
|
|
Another thing to be aware is that style comment will be sent with the web page while server side comments (using <%-- --%>) are stripped.
Philippe Mori
|
|
|
|
|
Well me and three other students develop a c# project as an exercise from University. We have been successfuly pushing it forward, spending about 3-4 hours a week on coding in a spare time. So far so good. Recently me and other colleague realized that one guy couldn't finish a simple task -- generate a PDF with a single table filled with data. Also, he has commited a code which didn't even compile, making some trouble for others. Now the punchline incoming. It came out that he:
1. has never coded C# before (Ruby is a preferred language for business apps so why bother with some MS sh*t)
2. hadn't use any C# compiler or installed any IDE (despite we have VS 2010 Ultimate from MSDNAA)
3. coded everything off-line and commited hoping that somebody would finally compile it and tell him that there were compilation errors.
4. did't use Windows. OK, but since we develop an app which target platform is Windows...
Ah -- and it's a 4th year of studying computer science. I feel like I missed something.
Greetings - Jacek
|
|
|
|
|
ah you got some of my old classmates I see, cant really do anything since they didn't bother to learn anything, and try to skate by on a team which is to nice to rat them out. oops, boy were they wrong about me on that part
Programming is a race between programmers trying to build bigger and better idiot proof programs, and the universe trying to build bigger and better idiots, so far... the universe is winning.
A graduation ceremony is an event where the commencement speaker tells thousands of students dressed in identical caps and gowns that 'individuality' is the key to success
|
|
|
|
|
gavindon wrote: nd try to skate by on a team which is to nice to rat them out
This isn't a case. He is full of a good will but he just does it wrong. And we like what we do so it doesn't really matter.
Greetings - Jacek
|
|
|
|
|
Just a stupid question: what does he expect to happen? It's not aq question for your team-members, just for him... I'm really curios about the answer...
(yes|no|maybe)*
|
|
|
|
|
s_mon wrote: Just a stupid question: what does he expect to happen? It's not aq question for your team-members, just for him... I'm really curios about the answer...
If I remember I will ask this question. The answer will probably be "I don't know", though.
Greetings - Jacek
|
|
|
|
|
that would the perfect start for me to do the "interrogation"...
(yes|no|maybe)*
|
|
|
|
|
I did ask the question. The answer was silence (embarassed? irritated? hard to say)... Unfortunately there wasn't any way to apply some tortures.
Greetings - Jacek
|
|
|
|
|
Even silence could be used but I guess, the mentioned embarassment was enough... hopefully to trigger a thought-process
(yes|no|maybe)*
|
|
|
|
|
What did his code look like?
I would be kinda impressed if what a C# newbie wrote without an IDE is still okay code
|
|
|
|
|
At the beginning of the file he wrote a manual how to use his class. Sth like: "You just set static fields to configure a thing and then invoke the X method, and then the PDF document will be written to file Y".
Greetings - Jacek
|
|
|
|