|
Timothy Baldwin wrote: As for discouraging reverse-engineering, this code is published under the GNU General Public Licence
If it weren't for the comments, that might explain it.
BTW, would the GPL require the release of source code for things like p-code which is interpreted by the rest of the program? What if the source code for the p-code never existed (because it was hand-generated)?
|
|
|
|
|
Too much code, too much writing. It could be done in a simple and write-only way like this:
byte mreadmem[ ] = {0x89,0xFA,0xC1,0xEA,0x0C,0x8B,...,0xC3 };
addbytes(mreadmem);
Sometimes if your code is crap it is better to asm it down to make others thinking "Uh, better not touch that".
Greetings - Gajatko
Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.
|
|
|
|
|
Here is a code i came across in my own project. Apparently I coded this when I was learning C# few years back. It gave me a good laugh now
bool isActive;
if (chkExamActive.Checked == false)
isActive = false;
else
isActive = true;
EDIT
OK I was just going through this old project of mine so here is another one in the same .cs file
ArrayList correctAnswers = new ArrayList();
correctAnswers.Add(txtPhrase.Text);
QuestionTableAdapter questionAdapter = new QuestionTableAdapter();
long QuestionID = questionAdapter.GetData()[0].QuestionID;
CorrectAnswerTableAdapter correctAnswerAdapter = new CorrectAnswerTableAdapter();
foreach (string correctAnswer in correctAnswers)
correctAnswerAdapter.Insert(correctAnswer, QuestionID);
Find the horror above
-------------------------------------------
It's code that drives you - Shyam
modified on Monday, November 24, 2008 11:26 AM
|
|
|
|
|
That sort of thing has been posted so often it has lost its horror.
|
|
|
|
|
Yeah even I saw this horror too many times here, so I expected this to have lost its horror...
I edited the post with one more horror I found. Hope this horror is not so common
-------------------------------------------
It's code that drives you - Shyam
|
|
|
|
|
bool isActive = chkExamActive.Checked;
This would cause issue if the checkbox were IsThreeState, because it has a third state, indetermintate. The code above could therefore give isActive a null value, therefore possibly causing issues later.
However, the code you posted is still crap.
|
|
|
|
|
My mistake for not mentioning it... This is code behind for ASP.net page so I guess IsThreeState situation wouldn't make my code great
-------------------------------------------
It's code that drives you - Shyam
|
|
|
|
|
Shyam Bharath wrote:
ArrayList correctAnswers = new ArrayList();
correctAnswers.Add(txtPhrase.Text);
QuestionTableAdapter questionAdapter = new QuestionTableAdapter();
long QuestionID = questionAdapter.GetData()[0].QuestionID;
CorrectAnswerTableAdapter correctAnswerAdapter = new CorrectAnswerTableAdapter();
foreach (string correctAnswer in correctAnswers)
correctAnswerAdapter.Insert(correctAnswer, QuestionID);
a few guesses at first glance:
0. no txtPhrase validation
1. questionAdapter will be empty since it is just only constructed (failure) -OR- it has a default, random (?) data entry or a static ID field acquiarable only by an instance method (horror).
2. [supposition:] question data is queried on each method call just to get an ID instead storing it somewhere.
3. correctAnswers contains just one element and so foreach loop is redutant.
are some of them correct?
Greetings - Gajatko
Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.
|
|
|
|
|
gajatko wrote: are some of them correct?
Cool. You got the third one correct. Let me explain others
gajatko wrote: 1. questionAdapter will be empty since it is just only constructed (failure) -OR- it has a default, random (?) data entry or a static ID field acquiarable only by an instance method (horror).
The adapter was generated by xsd tool and it fills data in the next line when I call GetData() method.
For point 2, good supposition . Luckily I didn't do that horror
gajatko wrote: 0. no txtPhrase validation
I have put validation controls in ASP.net WebForm. I guess that should be enough
Cool that you were able to identify the for loop one. You get my 5
-------------------------------------------
It's code that drives you - Shyam
|
|
|
|
|
idiotic code.
|
|
|
|
|
u r a champion to judge others?????/
|
|
|
|
|
CREATE TRIGGER tmTaskChangeHist ON Task FOR UPDATE, INSERT NOT FOR REPLICATION
as
begin
set nocount on
if not exists (select * from sysobjects where name = 'TaskChangeHist')
select * into TaskChangeHist from inserted
else
insert TaskChangeHist select * from inserted
set nocount off
end
Oh my. On top of this we have strict annotation guidelines at my company, which weren't followed there (note lack of comments :P)
Can someone please explain the thought process of checking whether TaskChangeHist exists, and then inserting anyway?
(not to mention the use of select *, although i guess it could be justified in this context)
|
|
|
|
|
Its fairly clear,
ruanr wrote: if not exists (select * from sysobjects where name = 'TaskChangeHist') select * into TaskChangeHist from inserted
creates TaskChangeHist if it doesn't exist (and inserts the record(s) from inserted), otherwise just insert the records.
The use of * is entirely justified (in my opinion) in this case. My only caveat would be that it will break if the Task table definition changes.
Not the best code to place in a trigger, but I can't see why you consider it a coding horror?
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Oh - I am a bit of a SQL novice, did not realize that 'select * into' will create a table. If that is the case, why is the 'ELSE' clause necessary?
And yes, Task got some extra col's, and so caused problems.
|
|
|
|
|
Well, if you don't need to create the table you do need to insert into it - hence the else.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
The use of a trigger is coding horror by itself.
|
|
|
|
|
You forgot this
Bob
Ashfield Consultants Ltd
|
|
|
|
|
My schoolmate told me about a situation he faced while coding using C#.
if we have the following code snippet :
public class Item
{
public int this[int y]
{
get
{
return 0;
}
}
}
While compiling an error will appear saying:
'Item': member names cannot be the same as their enclosing type
First I got confused, since I knew that I was defining indexer property for the class 'Item'.
After I referred to MSDN I read this :
Compiler Error CS0542
If your class is named 'Item' and has an indexer declared as this, you may get this error. A default indexer is given the name 'Item' in the emitted code, creating the conflict.
At the end I think that this MSIL specification mustn't be exist at all.
Best wishes,
Redwan Al-Bougha
|
|
|
|
|
This specification exists because other .NET languages such as VB.NET have to explicitly write it down. Think of Item as just another reserved word in C#.
Yes, MS could have chosen an ugly name like __MSIL$%Indexer%%__ or so, but what would it look like in VB or your documentation?
Regards
Thomas
www.thomas-weller.de
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. Programmer - an organism that turns coffee into software.
|
|
|
|
|
Thomas Weller wrote: This specification exists because other .NET languages such as VB.NET have to explicitly write it down.
That's right,
I think if a wrapper exist for each language between it's syntax and MSIL emitted code, this will help a lot.
Best wishes,
Redwan Al-Bougha
|
|
|
|
|
Redwan Al-Bougha wrote: I think if a wrapper exist for each language between it's syntax and MSIL emitted code
Well, such a 'wrapper' exists. They usually call it 'compiler'.
Regards
Thomas
www.thomas-weller.de
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. Programmer - an organism that turns coffee into software.
|
|
|
|
|
Thomas Weller wrote: They usually call it 'compiler'.
Thanks Thomas ,
I meant instead of :
1- Read language-specific syntax.
2- Convert code to MSIL code.
Do this :
1- Read language-specific syntax, where each language is not related in any way to MSIL code.
2- Convert code to MSIL code.
That's it avoid the happened ambiguity, as easy as this.
Or easily don't use common -reserved- words in any .NET language.
Best wishes,
Redwan Al-Bougha
|
|
|
|
|
You're missing the point. It's not that the MSIL code requires that the name of the property returned by the indexer be 'item', this is just a name that is auto generated by the compiler as a convenience. In your case, you have chosen the one and only class name that collides with the automatically generated name (and any name chosen for automatic generation will collide when used in a class of the same name). .Net also provides a convenient way to fix this: use an attribute to specify the name for the indexer so you can keep your class name as Item:
public class Item
{
[System.Runtime.CompilerServices.IndexerName("TheItem")]
public int this[int y]
{
get
{
return 0;
}
}
}
There is nothing to complain about here.
|
|
|
|
|
Rob Graham wrote: this is just a name that is auto generated by the compiler as a convenience
Thanks Rob,
That's what I wrote in the 1st post :
Redwan Al-Bougha wrote: A default indexer is given the name 'Item' in the emitted code, creating the conflict.
By the way thanks for your notice and for IndexerName attribute
Best Wishes,
Redwan Al-Bougha
|
|
|
|
|
This may more properly be in the Subtle Bugs forum, although it's not entirely subtle.
Anyway, my complaint wouldn't be that the indexer is considered to be named "Item"; I dont like the "member names cannot be the same as their enclosing type" part.
Why not? If I'm writing a Fibonacci method why shouldn't I put it in a class named Fibonacci?
|
|
|
|