Let's call him J. S. Crypt
-
...because his code (yes, I know it's a "he") and style reminds me of stuff I've seen in Javascript and other script languages.
public void Foo()
{
var SomeList = new ArrayList();
SomeList = getSomeList();if (SomeList.Count != 0) { foreach (string Item in SomeList) { var S = Item.Split(','); var S0 = s\[0\]; var S1 = s\[1\]; var S2 = s\[2\]; var S3 = s\[3\]; ... } } } private static ArrayList getSomeList() { var List = new ArrayList(); ... List.Add(N1 + "," + N2 + "," + N3 + "," + N3); ... return List; }
Variable names have for the most part been changed to protect the innocent. Things that got me laughing, cringing, and crying: 1. Useless initialization of SomeList 2. Well, if the count is 0, the
foreach
won't execute 3. Obviously never heard ofout
variables, or even returning a struct/class with the parsed data. Instead, he creates a concatenated string, then parses it back out! And not exactly internationalized, the chaos that would occur if one or more of the numbers was1234,56
4. Why a static method? It's referenced once, in the above call. And this is just the beginning! (I do believe this code was written in the .NET 2.0 days before generics -- I have other clues to that -- but that's no excuse.) MarcV.A.P.O.R.ware - Visual Assisted Programming / Organizational Representation Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802
Considering the use of
var
it must be at least .Net 3.5, unless of course that was part of protecting the innocent.Wrong is evil and must be defeated. - Jeff Ello
-
Considering the use of
var
it must be at least .Net 3.5, unless of course that was part of protecting the innocent.Wrong is evil and must be defeated. - Jeff Ello
Jörgen Andersson wrote:
Considering the use of
var
it must be at least .Net 3.5, unless of course that was part of protecting the innocent.Ah, good point. The vars were there in the original. It's really weird, it's as if the code was being compiled with C# (some version) but against an ancient version of .NET, because there's even reference elsewhere to
StringDictionary
which is pretty obsolete since generics. MarcV.A.P.O.R.ware - Visual Assisted Programming / Organizational Representation Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802
-
Marc Clifton wrote:
the .NET 2.0 days before generics
Did you mean the .NET 1.0 days? Generics were introduced with 2.0.
Marc Clifton wrote:
Why a static method?
Why not a static method? If it's not referencing any instance members, there are very few reasons to make it an instance method.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
Richard Deeming wrote:
Generics were introduced with 2.0.
Ah, my C# history is in error. Must self-destruct!
Richard Deeming wrote:
If it's not referencing any instance members, there are very few reasons to make it an instance method.
It's just weird. Why then require instantiating the class to call the public method, particularly if all it does is internally call private static methods? Marc
V.A.P.O.R.ware - Visual Assisted Programming / Organizational Representation Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802
-
Jörgen Andersson wrote:
Considering the use of
var
it must be at least .Net 3.5, unless of course that was part of protecting the innocent.Ah, good point. The vars were there in the original. It's really weird, it's as if the code was being compiled with C# (some version) but against an ancient version of .NET, because there's even reference elsewhere to
StringDictionary
which is pretty obsolete since generics. MarcV.A.P.O.R.ware - Visual Assisted Programming / Organizational Representation Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802
Or it is a person who seldom worked with .NET and had to bring up a solution for yesterday. I have the same issue with old code written in VB6 by "programmers" who at the time used QBasic (yes, first instance of our software worked under DOS). Besides, today there is .NET 4.6something, I only worked with 3.5 so I would probably write code which does not use any new functionality due to lack of experience / knowledge of them.
DURA LEX, SED LEX GCS d--- s-/++ a- C++++ U+++ P- L- E-- W++ N++ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t++ 5? X R++ tv-- b+ DI+++ D++ G e++>+++ h--- ++>+++ y+++* Weapons extension: ma- k++ F+2 X If you think 'goto' is evil, try writing an Assembly program without JMP. -- TNCaver When I was six, there were no ones and zeroes - only zeroes. And not all of them worked. -- Ravi Bhavnani
-
Richard Deeming wrote:
Generics were introduced with 2.0.
Ah, my C# history is in error. Must self-destruct!
Richard Deeming wrote:
If it's not referencing any instance members, there are very few reasons to make it an instance method.
It's just weird. Why then require instantiating the class to call the public method, particularly if all it does is internally call private static methods? Marc
V.A.P.O.R.ware - Visual Assisted Programming / Organizational Representation Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802
Exactly. Your complaint should have been that Foo *wasn't* static, not that getSomeList was.
-
Jörgen Andersson wrote:
Considering the use of
var
it must be at least .Net 3.5, unless of course that was part of protecting the innocent.Ah, good point. The vars were there in the original. It's really weird, it's as if the code was being compiled with C# (some version) but against an ancient version of .NET, because there's even reference elsewhere to
StringDictionary
which is pretty obsolete since generics. MarcV.A.P.O.R.ware - Visual Assisted Programming / Organizational Representation Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802
Like den2k88 wrote, it's probably someone not being used to the language, or even more likely, the framework. That parsing is just scary, but probably made by someone in a hurry.
Wrong is evil and must be defeated. - Jeff Ello
-
...because his code (yes, I know it's a "he") and style reminds me of stuff I've seen in Javascript and other script languages.
public void Foo()
{
var SomeList = new ArrayList();
SomeList = getSomeList();if (SomeList.Count != 0) { foreach (string Item in SomeList) { var S = Item.Split(','); var S0 = s\[0\]; var S1 = s\[1\]; var S2 = s\[2\]; var S3 = s\[3\]; ... } } } private static ArrayList getSomeList() { var List = new ArrayList(); ... List.Add(N1 + "," + N2 + "," + N3 + "," + N3); ... return List; }
Variable names have for the most part been changed to protect the innocent. Things that got me laughing, cringing, and crying: 1. Useless initialization of SomeList 2. Well, if the count is 0, the
foreach
won't execute 3. Obviously never heard ofout
variables, or even returning a struct/class with the parsed data. Instead, he creates a concatenated string, then parses it back out! And not exactly internationalized, the chaos that would occur if one or more of the numbers was1234,56
4. Why a static method? It's referenced once, in the above call. And this is just the beginning! (I do believe this code was written in the .NET 2.0 days before generics -- I have other clues to that -- but that's no excuse.) MarcV.A.P.O.R.ware - Visual Assisted Programming / Organizational Representation Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802
Did you notice this?
List.Add(N1 + "," + N2 + "," + N3 + "," + N3);
N3 is added twice. N4 is never added.
-
Did you notice this?
List.Add(N1 + "," + N2 + "," + N3 + "," + N3);
N3 is added twice. N4 is never added.
-
I thought he copied the code and changed what he wanted to preserve identity... So, it must be part of the real one. I think.
-
...because his code (yes, I know it's a "he") and style reminds me of stuff I've seen in Javascript and other script languages.
public void Foo()
{
var SomeList = new ArrayList();
SomeList = getSomeList();if (SomeList.Count != 0) { foreach (string Item in SomeList) { var S = Item.Split(','); var S0 = s\[0\]; var S1 = s\[1\]; var S2 = s\[2\]; var S3 = s\[3\]; ... } } } private static ArrayList getSomeList() { var List = new ArrayList(); ... List.Add(N1 + "," + N2 + "," + N3 + "," + N3); ... return List; }
Variable names have for the most part been changed to protect the innocent. Things that got me laughing, cringing, and crying: 1. Useless initialization of SomeList 2. Well, if the count is 0, the
foreach
won't execute 3. Obviously never heard ofout
variables, or even returning a struct/class with the parsed data. Instead, he creates a concatenated string, then parses it back out! And not exactly internationalized, the chaos that would occur if one or more of the numbers was1234,56
4. Why a static method? It's referenced once, in the above call. And this is just the beginning! (I do believe this code was written in the .NET 2.0 days before generics -- I have other clues to that -- but that's no excuse.) MarcV.A.P.O.R.ware - Visual Assisted Programming / Organizational Representation Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802
Possibly a cut and paste job from the internet by someone not familiar with C#, .NET or programming in general. Could well be a port out of C, C++ or VB6. Things like a private static method and module/global variables could be an artifact of another language.
-
...because his code (yes, I know it's a "he") and style reminds me of stuff I've seen in Javascript and other script languages.
public void Foo()
{
var SomeList = new ArrayList();
SomeList = getSomeList();if (SomeList.Count != 0) { foreach (string Item in SomeList) { var S = Item.Split(','); var S0 = s\[0\]; var S1 = s\[1\]; var S2 = s\[2\]; var S3 = s\[3\]; ... } } } private static ArrayList getSomeList() { var List = new ArrayList(); ... List.Add(N1 + "," + N2 + "," + N3 + "," + N3); ... return List; }
Variable names have for the most part been changed to protect the innocent. Things that got me laughing, cringing, and crying: 1. Useless initialization of SomeList 2. Well, if the count is 0, the
foreach
won't execute 3. Obviously never heard ofout
variables, or even returning a struct/class with the parsed data. Instead, he creates a concatenated string, then parses it back out! And not exactly internationalized, the chaos that would occur if one or more of the numbers was1234,56
4. Why a static method? It's referenced once, in the above call. And this is just the beginning! (I do believe this code was written in the .NET 2.0 days before generics -- I have other clues to that -- but that's no excuse.) MarcV.A.P.O.R.ware - Visual Assisted Programming / Organizational Representation Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802
If you are hyper-optimizing code, you can avoid allocation of an enumerator object by checking the count first if you expect that it will often contain 0 items. That said, it is obvious that this guy probably wouldn't know that, but worth noting. We've done it in very performance sensitive code that might be called many times in a tight loop.
-
If you are hyper-optimizing code, you can avoid allocation of an enumerator object by checking the count first if you expect that it will often contain 0 items. That said, it is obvious that this guy probably wouldn't know that, but worth noting. We've done it in very performance sensitive code that might be called many times in a tight loop.
Better to avoid
foreach
whenever possible. If there's aCount
, it's probably indexable, so usefor
instead. -
Better to avoid
foreach
whenever possible. If there's aCount
, it's probably indexable, so usefor
instead.For performance sensitive code that could be used in long tight loops I agree, but "whenever" I don't agree with. In 95% of code it will make zero difference, so the readability and simplicity of foreach wins.
-
...because his code (yes, I know it's a "he") and style reminds me of stuff I've seen in Javascript and other script languages.
public void Foo()
{
var SomeList = new ArrayList();
SomeList = getSomeList();if (SomeList.Count != 0) { foreach (string Item in SomeList) { var S = Item.Split(','); var S0 = s\[0\]; var S1 = s\[1\]; var S2 = s\[2\]; var S3 = s\[3\]; ... } } } private static ArrayList getSomeList() { var List = new ArrayList(); ... List.Add(N1 + "," + N2 + "," + N3 + "," + N3); ... return List; }
Variable names have for the most part been changed to protect the innocent. Things that got me laughing, cringing, and crying: 1. Useless initialization of SomeList 2. Well, if the count is 0, the
foreach
won't execute 3. Obviously never heard ofout
variables, or even returning a struct/class with the parsed data. Instead, he creates a concatenated string, then parses it back out! And not exactly internationalized, the chaos that would occur if one or more of the numbers was1234,56
4. Why a static method? It's referenced once, in the above call. And this is just the beginning! (I do believe this code was written in the .NET 2.0 days before generics -- I have other clues to that -- but that's no excuse.) MarcV.A.P.O.R.ware - Visual Assisted Programming / Organizational Representation Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802
Oh, now I am reminded of some ODBC code (in ANSI C) I had thrust upon me in the late-90s -- query results were returned as CSV strings. :omg: I had to write my own version that at least returned sort of an array of strings.
-
Did you notice this?
List.Add(N1 + "," + N2 + "," + N3 + "," + N3);
N3 is added twice. N4 is never added.
Paulo Zemek wrote:
N3 is added twice.
That was my typo. ;) Marc
V.A.P.O.R.ware - Visual Assisted Programming / Organizational Representation Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802
-
Paulo Zemek wrote:
N3 is added twice.
That was my typo. ;) Marc
V.A.P.O.R.ware - Visual Assisted Programming / Organizational Representation Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802
Hehe... OK. I thought I was another coding horror... you know, complete lack of testing.