Superman if-clause
-
just looked into the code of an project made from a workmate. may be he thought superman would fly in and delete the folder between the two if-clauses xD
if (System.IO.Directory.Exists(dest))
{
if (!System.IO.Directory.Exists(dest))
{
System.IO.Directory.CreateDirectory(dest);
}fullDest = dest + fileInfo.Name; // what is if Directory seperator is missing? xD
}
freakyit wrote:
may be he thought superman would fly in and delete the folder between the two if-clauses
this could actually happen in a multi threaded environment but then he would fly by again after the creation and delete it again =/
-
just looked into the code of an project made from a workmate. may be he thought superman would fly in and delete the folder between the two if-clauses xD
if (System.IO.Directory.Exists(dest))
{
if (!System.IO.Directory.Exists(dest))
{
System.IO.Directory.CreateDirectory(dest);
}fullDest = dest + fileInfo.Name; // what is if Directory seperator is missing? xD
}
Looks like a classic example of code that originally did more than this. After the "more" was moved to somewhere else, this snippet was what was left behind. I've seen many examples and they always make the original programmer look really stupid. Have to admit - I've even done it myself :-)
-
just looked into the code of an project made from a workmate. may be he thought superman would fly in and delete the folder between the two if-clauses xD
if (System.IO.Directory.Exists(dest))
{
if (!System.IO.Directory.Exists(dest))
{
System.IO.Directory.CreateDirectory(dest);
}fullDest = dest + fileInfo.Name; // what is if Directory seperator is missing? xD
}
Shurely,
string IsSuperman() {
if (IsItABird())
return "Bird";
else if (IsItAPlane())
return "Plane";
else
return "Superman";
}(Sorry - its a bad job, but someone's gotta do it.)
-
Shurely,
string IsSuperman() {
if (IsItABird())
return "Bird";
else if (IsItAPlane())
return "Plane";
else
return "Superman";
}(Sorry - its a bad job, but someone's gotta do it.)
-
just looked into the code of an project made from a workmate. may be he thought superman would fly in and delete the folder between the two if-clauses xD
if (System.IO.Directory.Exists(dest))
{
if (!System.IO.Directory.Exists(dest))
{
System.IO.Directory.CreateDirectory(dest);
}fullDest = dest + fileInfo.Name; // what is if Directory seperator is missing? xD
}
Did you just not READ the comment? He's concerned that the path separator is missing from the end of the dest variable. A not unreasonable concern. Your coworker knows about the System.IO namespace.. but apparently not the Path object. Path.Combine() is what he's in need of.
-
just looked into the code of an project made from a workmate. may be he thought superman would fly in and delete the folder between the two if-clauses xD
if (System.IO.Directory.Exists(dest))
{
if (!System.IO.Directory.Exists(dest))
{
System.IO.Directory.CreateDirectory(dest);
}fullDest = dest + fileInfo.Name; // what is if Directory seperator is missing? xD
}
This leads me to once again point out how important that cup of coffee is before commencing to write any code. :)
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
-
This leads me to once again point out how important that cup of coffee is before commencing to write any code. :)
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
-
Did you just not READ the comment? He's concerned that the path separator is missing from the end of the dest variable. A not unreasonable concern. Your coworker knows about the System.IO namespace.. but apparently not the Path object. Path.Combine() is what he's in need of.
Path.Combine doesn't always work as one would wish
-
just looked into the code of an project made from a workmate. may be he thought superman would fly in and delete the folder between the two if-clauses xD
if (System.IO.Directory.Exists(dest))
{
if (!System.IO.Directory.Exists(dest))
{
System.IO.Directory.CreateDirectory(dest);
}fullDest = dest + fileInfo.Name; // what is if Directory seperator is missing? xD
}
Both the exists checks are unneeded. A manual would be more appropriate. The FMSDN says: If the directory already exists, this method does nothing.
xacc.ide
IronScheme - 1.0 RC 1 - out now!
((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition -
just looked into the code of an project made from a workmate. may be he thought superman would fly in and delete the folder between the two if-clauses xD
if (System.IO.Directory.Exists(dest))
{
if (!System.IO.Directory.Exists(dest))
{
System.IO.Directory.CreateDirectory(dest);
}fullDest = dest + fileInfo.Name; // what is if Directory seperator is missing? xD
}
we cant know! we cant judge.its windows afterall :D
d'Oh!