|
Make the constant string a resource and put the constant ints in the config.
|
|
|
|
|
No no no... It's harder to hide it that way.
With code like this, you want it buried deeply inside a commonly-used DLL in a not-quite-obsolete language, so when you get laid off and the next guy in line decides to rewrite the code and modernize it, they have a heart attack when they see it.
At least, That was probably what some of my predecessors were thinking...
|
|
|
|
|
Ian Shlasko wrote: It's harder to hide it that way.
No, it hides it in different places; your way has all the information in one place.
Plus, using a resource and config makes it brittle -- if someone changes or removes the entries chaos will ensue.
|
|
|
|
|
Nah, the point is that everything looks normal from the outside... Then you drill down into the utility functions, and each one is completely illegible. So you've already ported half of the library, and now you don't want to touch it because you're afraid you'll miss something and break an edge condition.
|
|
|
|
|
Nice thinking, job security at it's best.
|
|
|
|
|
I should have placed the joke icon.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
Tcha! The youth and inexperience shows! Every real programmer knows that the best compression method is to use a random number generator with the correct seed to regenerate the uncompressed file - then all you need to do is send the seed. Extending this:
Random rs;
const string blarphnik = "51209576120381929170992";
int dontTouchThis = int.Parse(blarphnik.Substring(12,1));
rs = new Random(dontTouchThis);
StringBuilder sb = new StringBuilder(2);
sb.Append(Convert.ToChar(rs.Next(15)));
int dontTouchThisEither = int.Parse(blarphnik.Substring(10,1));
rs = new Random(dontTouchThisEither);
sb.Append(Convert.ToChar(rs.Next(15)));
string cBRK = sb.ToString();
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
"Rumour has it that if you play Microsoft CDs backwards you will hear Satanic messages.Worse still, is that if you play them forwards they will install Windows"
|
|
|
|
|
Oh right, I totally forgot about that... But you have to comment your code to make sure it's legible!
Random rs;
const string blarphnik = "51209576120381929170992";
int dontTouchThis = int.Parse(blarphnik.Substring(12,1));
rs = new Random(dontTouchThis );
StringBuilder sb = new StringBuilder(2);
sb.Append(Convert.ToChar(rs.Next(15)));
int dontTouchThisEither = int.Parse(blarphnik.Substring(10,1));
rs = new Random(dontTouchThisEither );
sb.Append(Convert.ToChar(rs.Next(15)));
string cBRK = sb.ToString();
|
|
|
|
|
Ian Shlasko wrote: self-help book
Ian Shlasko wrote: How to Drive a Programmer Insane
So your target audience, precisely, is ...?
Personally, I love the idea that Raymond spends his nights posting bad regexs to mailing lists under the pseudonym of Jane Smith. He'd be like a super hero, only more nerdy and less useful. [Trevel] | FoldWithUs! | sighist | µLaunch - program launcher for server core and hyper-v server
|
|
|
|
|
peterchen wrote: So your target audience, precisely, is ...?
I don't think that far ahead
|
|
|
|
|
sane programmers with good reading skills, not a big audience IMO.
|
|
|
|
|
A BASIC developer new to C#?
jofli wrote: Recieved
And maybe didn't graduate high school either?
|
|
|
|
|
PIEBALDconsult wrote: A BASIC developer new to C#?
No way. Any Basic developer would use either Chr$(13) & Chr$(10) or vbCrLf , both much more readable than the OP.
|
|
|
|
|
PIEBALDconsult wrote: jofli wrote:
Recieved
And maybe didn't graduate high school either? Big Grin
http://www.recieved.co.uk/[^]
Well, at least he tried to use English namings. And I must admit that sometimes it's not that easy, if you're not a native speaker.
|
|
|
|
|
My guess is that this is an artifact of Reflector, not of the original coder.
I do know that in VB, the Chr() function actually does use Convert.ToChar internally so my guess is that C# does the same. Who knows what Environment.NewLine does internally. I assume that the compiler has in-lined the Chr function, and Reflector has simply given you back what the compiler produced. Anyone with too much free time on their hands and a handy copy of Reflector is invited to experiment to find out what the compiler does with this sort of thing.
Reflector is showing you what the code looks like after the compiler has munged it around and played merry havoc with your beautiful code.
|
|
|
|
|
OK, there is no Chr function in C# but you know what I mean.
|
|
|
|
|
The correct code in C# is "\r\n" which is ldstr "\r\n" in MSIL (which is generated exactly like that by the C# compiler)
|
|
|
|
|
The OP doesn't say that the code was written in C#, it was reverse engineered using Reflector. Reflector is capable of taking code written in VB and decompiling it back into C#. The resulting C# code may look pretty odd, but you will at least be able to see what it is doing.
|
|
|
|
|
That's right, but afaik he only codes c#.
|
|
|
|
|
Well, OK, maybe he's just an idiot. As far as I am aware, Reflector doesn't stop people from writing bad code and will happily decompile bad C# back into bad C#. GIGO, as they say.
For what it's worth, the MS .NET Framework implementation of C# Environment.NewLine returns a literal constant "\r\n". No idea what Mono does. So if the contractor wrote this in C#, goodness only knows what was going through his brain. Nothing, probably, if he's like some of the contractors I've known.
|
|
|
|
|
The Chr() = Convert.ToChar() thing makes some sense, but why int.Parse("13") instead of just 13?
|
|
|
|
|
Looks like temp = Chr(13) + Chr(10) gets decompiled into temp = "\r\n"; so the compiler is smart enough to actually make the string when you call Chr with a constant. Environment.NewLine shows up as a property call in Reflector, but the JIT may inline it as a literal string.
There's no way Reflector would generate what the OP is seeing unless the code really was that bad.
|
|
|
|
|
Come to think of it, why are you having to reverse engineer the contractor's project? If he wrote the code while in your employ, I would expect that you would own the intellectual property rights to the code, and normally you would expect to have a copy of the source after his contract ends.
Unless you bought this from him as a finished product rather than contracting his time to write it for you. In which case, he owns the copyright and reverse engineering it could be a breach of the licence terms (which normally forbid that sort of thing).
|
|
|
|
|
David Skelly wrote: reverse engineering it could be a breach of the licence terms (which normally forbid that sort of thing)
Perhaps this could be the reason exactly why they forbid reverse engineering?
|
|
|
|
|