Code Puzzle
-
How many compiler errors, potential NullReferenceExceptions, StackOverflowExceptions and whatnot can you spot in this presumably review-ready class? And the million dollar question: Can you guess the intended purpose?
public class QueryContainer
{
private static List<QueryContainer> Container;
private static QueryContainer instance;public static QueryContainer Instance { get { if (Instance == null) instance = new QueryContainer(); return instance; } } public int \_searchID; public int ID { get { return \_id; } } public string Query { get { return Container.Find(instance => instance.\_id == \_searchID).Query; } set { Container.Query = value; \_id =+ 1; } } private int \_id; private string \_query; private QueryContainer() { }
}
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
-
How many compiler errors, potential NullReferenceExceptions, StackOverflowExceptions and whatnot can you spot in this presumably review-ready class? And the million dollar question: Can you guess the intended purpose?
public class QueryContainer
{
private static List<QueryContainer> Container;
private static QueryContainer instance;public static QueryContainer Instance { get { if (Instance == null) instance = new QueryContainer(); return instance; } } public int \_searchID; public int ID { get { return \_id; } } public string Query { get { return Container.Find(instance => instance.\_id == \_searchID).Query; } set { Container.Query = value; \_id =+ 1; } } private int \_id; private string \_query; private QueryContainer() { }
}
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
-
Clue bat needed in Aisle 5! Clue bat needed in Aisle 5!
What do you get when you cross a joke with a rhetorical question? The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism. Do questions with multiple question marks annoy you???
-
Yes, I saw it.. sighed, and decided to let someone else answer since he apparently didn't believe me :sigh:
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
-
How many compiler errors, potential NullReferenceExceptions, StackOverflowExceptions and whatnot can you spot in this presumably review-ready class? And the million dollar question: Can you guess the intended purpose?
public class QueryContainer
{
private static List<QueryContainer> Container;
private static QueryContainer instance;public static QueryContainer Instance { get { if (Instance == null) instance = new QueryContainer(); return instance; } } public int \_searchID; public int ID { get { return \_id; } } public string Query { get { return Container.Find(instance => instance.\_id == \_searchID).Query; } set { Container.Query = value; \_id =+ 1; } } private int \_id; private string \_query; private QueryContainer() { }
}
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
Among all the toe-curling flaws in there, these are my two favorites: It's not even a singleton - it's a "noneton": Trying to access the Instance-property will cause a stack overflow due to recursion.. The List<QueryContainer> will be really, really short. Even when fixing the above flaw.. And the answer to the million dollar question: It's supposed to somehow (don't ask me) help with fixing code that is vulnerable to SQL-injection.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
-
Threading issues certainly. What language?
PIEBALDconsult wrote:
Threading issues certainly.
You're WAY off :laugh: (See my solution-post below)
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
-
Among all the toe-curling flaws in there, these are my two favorites: It's not even a singleton - it's a "noneton": Trying to access the Instance-property will cause a stack overflow due to recursion.. The List<QueryContainer> will be really, really short. Even when fixing the above flaw.. And the answer to the million dollar question: It's supposed to somehow (don't ask me) help with fixing code that is vulnerable to SQL-injection.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
The new version[^] still doesn't fix the problem. I'm running out of different ways to explain to him why his approach isn't going to work. :sigh:
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
The new version[^] still doesn't fix the problem. I'm running out of different ways to explain to him why his approach isn't going to work. :sigh:
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
He might be impervious to advice..
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
-
The new version[^] still doesn't fix the problem. I'm running out of different ways to explain to him why his approach isn't going to work. :sigh:
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
I know one remarkably effective way to explain to him: use SQL Injection to delete his database. And every time he puts it back, it goes again. It's cruel. It's nasty. It's probably illegal. But it's what his best mate will do, just to see the look on his face...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
-
Among all the toe-curling flaws in there, these are my two favorites: It's not even a singleton - it's a "noneton": Trying to access the Instance-property will cause a stack overflow due to recursion.. The List<QueryContainer> will be really, really short. Even when fixing the above flaw.. And the answer to the million dollar question: It's supposed to somehow (don't ask me) help with fixing code that is vulnerable to SQL-injection.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
Sascha Lefèvre wrote:
It's supposed to somehow (don't ask me) help with fixing code that is vulnerable to SQL-injection.
After reading the actual questions, I don't think he is trying to fix the actual vulnerability with his code. Instead he may be trying to cheat the test system (by obfuscation) from detecting that there is an SQL injection vulnerability.
The good thing about pessimism is, that you are always either right or pleasently surprised.
-
How many compiler errors, potential NullReferenceExceptions, StackOverflowExceptions and whatnot can you spot in this presumably review-ready class? And the million dollar question: Can you guess the intended purpose?
public class QueryContainer
{
private static List<QueryContainer> Container;
private static QueryContainer instance;public static QueryContainer Instance { get { if (Instance == null) instance = new QueryContainer(); return instance; } } public int \_searchID; public int ID { get { return \_id; } } public string Query { get { return Container.Find(instance => instance.\_id == \_searchID).Query; } set { Container.Query = value; \_id =+ 1; } } private int \_id; private string \_query; private QueryContainer() { }
}
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
"But please - no programming questions."
-
"But please - no programming questions."
As you didn't mark your post as a joke or put a smiley into it I have to assume you're being serious: But my post isn't a programming question.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
-
How many compiler errors, potential NullReferenceExceptions, StackOverflowExceptions and whatnot can you spot in this presumably review-ready class? And the million dollar question: Can you guess the intended purpose?
public class QueryContainer
{
private static List<QueryContainer> Container;
private static QueryContainer instance;public static QueryContainer Instance { get { if (Instance == null) instance = new QueryContainer(); return instance; } } public int \_searchID; public int ID { get { return \_id; } } public string Query { get { return Container.Find(instance => instance.\_id == \_searchID).Query; } set { Container.Query = value; \_id =+ 1; } } private int \_id; private string \_query; private QueryContainer() { }
}
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
1. The
Instance
property get will overflow the stack due to recursion. 2. TheQuery
property set and get will both throwNullReferenceException
's, sinceContainer
is never initialized. 3. The code shouldn't even compile. TheQuery
property set assignsvalue
toContainer.Query
, but sinceContainer
is aList<>
, it doesn't have aQuery
property. I'm going to completely ignore the code's stated purpose, which I don't think what they've provided has the faintest hope of meeting.Software Zen:
delete this;
-
As you didn't mark your post as a joke or put a smiley into it I have to assume you're being serious: But my post isn't a programming question.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
Here's your smiley: :) :-D :laugh: ;) ;P :^) :( :sigh: :doh: :(( :zzz: :-\ :omg: :rolleyes: :-O :wtf: :mad::confused: X| :| :~:suss::cool: Pick the one you like best. Only one per member.
-
Here's your smiley: :) :-D :laugh: ;) ;P :^) :( :sigh: :doh: :(( :zzz: :-\ :omg: :rolleyes: :-O :wtf: :mad::confused: X| :| :~:suss::cool: Pick the one you like best. Only one per member.
You forgot a few: :baaaa!: :badger: :beer: :bob: :eek: :java: :jig: :vegemite:
Wrong is evil and must be defeated. - Jeff Ello
-
Here's your smiley: :) :-D :laugh: ;) ;P :^) :( :sigh: :doh: :(( :zzz: :-\ :omg: :rolleyes: :-O :wtf: :mad::confused: X| :| :~:suss::cool: Pick the one you like best. Only one per member.
I'll take the second one, please. Can you wrap it as a gift? ;P
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
-
I'll take the second one, please. Can you wrap it as a gift? ;P
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
****** * :-D * ******
-
****** * :-D * ******
Very nice, will order again ;)
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson