Comment On A Constant ... Constant?

We've seen some pretty pointless constants defined before. And again. So it shouldn't come as a huge shock to see Colin's colleague define a line break constant instead of using "\r\n". Or using Environment.NewLine. Or using a property to define the constant instead of ... oh ... say ... a constant. Or taking six lines to return a simple, two-character string. But naming it CRLF? 'Sup with that?!? [expand full text]
« PrevPage 1 | Page 2Next »

Re: A Constant ... Constant?

2005-01-19 13:56 • by
[:'(]  Just another reason to cry!  WTF is this dude thinking?

Re: A Constant ... Constant?

2005-01-19 13:58 • by seizethedave
Initech eh? (office space)

Re: A Constant ... Constant?

2005-01-19 14:02 • by Maurits
28122 in reply to 28120
I guess he thought the one-liner

return ((char)13).ToString() + ((char)10).ToString();

was too confoozing. ;-)

Re: A Constant ... Constant?

2005-01-19 14:08 • by
28123 in reply to 28122

Oh no, that guy is SOOO stupid; if he programs this way his app is not portable at all !


I mean, it doesn't even have a LF function to return the newline character when his app is gonna run on unix on a ported .net framework ...


What a n00b!


... erm, that is the wtf isn't it ?


guys?


*sound of crickets*

Re: A Constant ... Constant?

2005-01-19 14:20 • by Blue
28124 in reply to 28123

That is certainly ONE of them, in addition to the several which Alex mentioned in the intro post..


So where's the triumphant "see, something horrible in a language other than VB!"?  Guess they won't stoop to "our" level.  [:)]


 


 

Re: A Constant ... Constant?

2005-01-19 14:46 • by
You know, I just HAVE to say that I think a number of regular posters here really need their sarcasm detectors repaired.



You DO have a sarcasm detector, don't you?

Re: A Constant ... Constant?

2005-01-19 14:56 • by Scott
28127 in reply to 28125
:
You know, I just HAVE to say that I think a number of
regular posters here really need their sarcasm detectors repaired.



You DO have a sarcasm detector, don't you?





I do.  You were being serious weren't you?

Re: A Constant ... Constant?

2005-01-19 15:13 • by
Your RSS feed keeps saying any items in it are new. This is obviously
kind of annyoing, so I was wondering if you could maybe just fix it?
Since you're apparently using a forum, changing the RSS feed to return
the topicstart-date rather than the last-post date would probably work.

Re: A Constant ... Constant?

2005-01-19 15:27 • by memorex
WoW! Now THAT is a good one!



Re: A Constant ... Constant?

2005-01-19 15:31 • by

public static string CRLF = "/r/n";


to me that's a lot cleaner...

Re: A Constant ... Constant?

2005-01-19 15:53 • by seizethedave
Tame your RSS you heathen.

Re: A Constant ... Constant?

2005-01-19 15:55 • by
28134 in reply to 28132

\r\n

Re: A Constant ... Constant?

2005-01-19 16:07 • by kentcb
28135 in reply to 28134

Environment.NewLine is the way to go. Notice they didn't call it Environment.CRLF [:P]


I think this board needs a sarcasm emoticon. Way too many people get confused. Or perhaps we need a non-sarcasm emoticon and we just assume sarcasm by default.

Re: A Constant ... Constant?

2005-01-19 16:34 • by brandonh6k
Maybe I'm missing something here, but what about the vbCRLF constant?  Was that too obvious?

Re: A Constant ... Constant?

2005-01-19 16:39 • by phx
Its someone who has just discovered OO. Wow I could like "properly encapsulate" that in a class! And encapsulate that! In fact I wont add more than one method per level of inheritance.....

Re: A Constant ... Constant?

2005-01-19 16:51 • by Alex Papadimoulis
28140 in reply to 28136

brandonh6k:
Maybe I'm missing something here, but what about the vbCRLF constant?  Was that too obvious?


This is C#. vbCrLf is only in VB. Hence the "vb" prefix. [:P]


I suppose, however, he could have referenced Microsoft.VisualBasic.dll and used ControlChars.NewLine ...

Re: A Constant ... Constant?

2005-01-19 16:56 • by
28141 in reply to 28137

Only thing worse would have been to make it a non static property.


 

Re: A Constant ... Constant?

2005-01-19 16:57 • by
I honestly wouldn't be *that* worried about cross-platform behavior... Especially in .NET.  What a waste of time.  It's almost like the person created it to show off their casting ability. 

Re: A Constant ... Constant?

2005-01-19 17:17 • by brandonh6k
28145 in reply to 28140
Alex Papadimoulis:








 brandonh6k wrote:




Maybe I'm missing something here, but what about the vbCRLF constant?  Was that too obvious?


This is C#. vbCrLf is only in VB. Hence the "vb" prefix. Stick out tongue


I suppose, however, he could have referenced Microsoft.VisualBasic.dll and used ControlChars.NewLine ...



Well, duh... [:$] I guess my brain is in neutral today.  I looked at it earlier and my brain said VB...  Too much coding with not enough caffeine today.

Re: A Constant ... Constant?

2005-01-19 17:29 • by redtetrahedron
28147 in reply to 28120

seizethedave:
Initech eh? (office space)


Yea, I noticed that too. [8-|] Note the comment below the namespace


//namespace changed to protect the guilty


 

Re: A Constant ... Constant?

2005-01-19 17:31 • by seizethedave
28149 in reply to 28147
redtetrahedron:








 seizethedave wrote:




Initech eh? (office space)


Yea, I noticed that too. [8-|] Note the comment below the namespace


//namespace changed to protect the guilty



I'm a lazy reader.

Re: A Constant ... Constant?

2005-01-19 17:33 • by
Have you tried Javascript? LOL

Re: A Constant ... Constant?

2005-01-19 17:47 • by JoeNotCharles
28152 in reply to 28135
If this is to be sent over the wire (like HTTP) the standard says "CRLF", not "whatever your platform thinks is the end of a line". (Apparently there are actually broken web servers that will send bare CR's or LF's - why should clients have to deal with that?) And it's definitely better to make a constant than type "\r\n" all over the place, because if you accidentally type "\t\n" the compiler will catch it. So the only WTF here is the bizarre implementation - the concept is laudable.

Re: A Constant ... Constant?

2005-01-19 18:44 • by Katja
It might be a WTF, but at least the code is working and doing exactly what is required. It returns a #13#10 as result. (You do know how to read Delphi code, do you? [:P])

Re: A Constant ... Constant?

2005-01-19 19:06 • by foxyshadis
This way he's protected in case the string delimeter characters ever change. ^_^



(I couldn't resist. xD)



This reminds me of XSLT; maybe the guy grew up there or in another
language similarly restricted. XSLT's formatting is entirely implicit
and generally implementation-defined - it works great for xml and html,
when you don't care how the code looks, but it sucks for text out. So
you have to define a newline to save yourself the burden of
copy-pasting two long lines of code (!) every time, and whole functions
just for each printf.



XSL is a lot like Java. It started out as a quickie language to fill a
void - quick, easy, and simple translation of XML into other things by
a few web developers - but it spiraled into a general purpose language.
Not being designed for it, it sucks. (I happen to think it's fun and
still the best way to access XML, but procedural languages are finally
catching up, thankfully.)

Re: A Constant ... Constant?

2005-01-19 22:21 • by
28165 in reply to 28132
Indeed, "/r/n" is a lot better than the OP's solution. It's almost twice as good, since it uses 4 bytes instead of the pathetic 2.

Re: A Constant ... Constant?

2005-01-19 22:23 • by
28166 in reply to 28132
:

public static string CRLF = "/r/n";


to me that's a lot cleaner...









Indeed, "/r/n" is a lot better than the OP's solution. It's almost
twice as good, since it uses 4 bytes instead of the pathetic 2.

Re: A Constant ... Constant?

2005-01-20 00:04 • by
28168 in reply to 28166
Wow. It is \r\n, not /r/n.

Re: A Constant ... Constant?

2005-01-20 03:26 • by aapopfriets
28171 in reply to 28124
Blue:

That is certainly ONE of them, in addition to the several which Alex mentioned in the intro post..


So where's the triumphant "see, something horrible in a language other than VB!"?  Guess they won't stoop to "our" level.  Smile


 


 

Re: A Constant ... Constant?

2005-01-20 03:28 • by aapopfriets
28172 in reply to 28124
Blue:

That is certainly ONE of them, in addition to the several which Alex mentioned in the intro post..


So where's the triumphant "see, something horrible in a language other than VB!"?  Guess they won't stoop to "our" level.  Smile


 


 

Re: A Constant ... Constant?

2005-01-20 03:29 • by aapopfriets
28173 in reply to 28124
Blue:

That is certainly ONE of them, in addition to the several which Alex mentioned in the intro post..


So where's the triumphant "see, something horrible in a language other than VB!"?  Guess they won't stoop to "our" level.  Smile


 


 

Re: A Constant ... Constant?

2005-01-20 03:30 • by aapopfriets
28174 in reply to 28173
Allright forum, you win. I give up trying to quote.



"Note that this is still .NET,  so it's nothing like C/C++. Seeing as
there are more C# WTFs than C/C++ WTFs, I state that C# == VB."




Re: A Constant ... Constant?

2005-01-20 07:03 • by Unforgiven
28179 in reply to 28174

Someone here mentioned vbCrLf... actually you can use that in C# (kinda), by referencing the Microsoft.VisualBasic assembly and then using Microsoft.VisualBasic.ControlChars.CrLf.


More to the point however, in all circumstances that I can think of, in C# a single \n will be seen as a line break. Unless you're writing a file in binary mode, you're not going to need \r\n. And even then there's the Environment.NewLine constant, which is automatically set to the correct character sequence for the platform.

Re: A Constant ... Constant?

2005-01-20 07:31 • by
Note that if someone's using "\r\n" they don't necessarily want
Environment.NetLine - they might require CR-LF for a protocol,
for example.

Re: A Constant ... Constant?

2005-01-20 08:33 • by alexb
28186 in reply to 28157

foxyshadis:
This reminds me of XSLT; maybe the guy grew up there or in another language similarly restricted. XSLT's formatting is entirely implicit and generally implementation-defined - it works great for xml and html, when you don't care how the code looks, but it sucks for text out. So you have to define a newline to save yourself the burden of copy-pasting two long lines of code (!) every time, and whole functions just for each printf.

XSL is a lot like Java. It started out as a quickie language to fill a void - quick, easy, and simple translation of XML into other things by a few web developers - but it spiraled into a general purpose language. Not being designed for it, it sucks. (I happen to think it's fun and still the best way to access XML, but procedural languages are finally catching up, thankfully.)


If you're going to start dissing XSL, we'll need to go outside and have some words.


 Seriously, comparing XSL and Java? I've never heard of two things more different. The only thing they have in common is that ... because they... since they both... ummm...  they have absolutely nothing in common!


C'mon now. If it's not designed for something you need, don't use it! pfft.

Re: A Constant ... Constant?

2005-01-20 08:55 • by
28189 in reply to 28181
:
Note that if someone's using "\r\n" they don't necessarily want
Environment.NetLine - they might require CR-LF for a protocol,
for example.





Yeah, I've used vbCrLf a lot over the past week.



A message must...end with a 'carriage return - line feed' (CRLF)...




Underlines and bolds straight from the MODBUS specs.  Wouldn't a WTF in that case be using NewLine?

Re: A Constant ... Constant?

2005-01-20 09:20 • by JamesCurran
28191 in reply to 28174

"Note that this is still .NET,  so it's nothing like C/C++. Seeing as there are more C# WTFs than C/C++ WTFs, I state that C# == VB."


Um... No.   I'd say this is clearly the work of a C programmer writing his first C# program.   Who else would cast an int to a char?


 

Re: A Constant ... Constant?

2005-01-20 09:55 • by
28197 in reply to 28120

Re: A Constant ... Constant?

2005-01-20 10:20 • by
28199 in reply to 28150
:
Have you tried Javascript? LOL


genius

Re: A Constant ... Constant?

2005-01-20 10:26 • by
In defense of this code, I can think of one sensible reason for it: the original developer is an old Java developer.



The problem is that "\n" doesn't mean 0x10.  It means
"end-of-line."  Which means that if you compile "\n" on a platform
that uses a different end-of-line character (read: Mac OS Classic),
your code will not generate 0x10, but 0x13 instead (on Mac Classic, anyway, since \r and \n are swapped there).



Consequently, if you're trying to write portable code that needs to
work with binary internet protocols (such as SMTP, which requires 0x13
0x10 as a line terminator in some sections), you can not blindly use "\r\n", since it will fail in some locations.



However, Mac Classic is virtually dead as a development platform, and I
know of no other platform that doesn't follow the Windows/Unix line ending
conventions, so this probably isn't an issue.



Lack of portability of C# to a Mac is a non-starter; C# code can run on Mac OS X, through Mono and Portable.NET, though Mac OS X follows Unix line ending conventions, so "\r\n" should still be portable.

Re: A Constant ... Constant?

2005-01-20 11:54 • by

"Seriously, comparing XSL and Java? I've never heard of two things more different. The only thing they have in common is that ... because they... since they both... ummm...  they have absolutely nothing in common!"


They're both turing complete.

Re: A Constant ... Constant?

2005-01-21 03:40 • by aapopfriets
28266 in reply to 28191
JamesCurran:

"Note
that this is still .NET,  so it's nothing like C/C++. Seeing as
there are more C# WTFs than C/C++ WTFs, I state that C# == VB."


Um... No.   I'd say this is clearly the work of a C programmer writing his first C# program.   Who else would cast an int to a char?


 




Any C programmer that thinks assigning 10 or 13 to a char needs a cast, is not a C programmer.


Re: A Constant ... Constant?

2005-01-23 09:07 • by

What ever happened to just using the framework

[code language="c#"]

System.Environment.NewLine

[/code]

McGiv

Re: A Constant ... Constant?

2005-01-24 08:45 • by

He could use the stringbuilder to concatenate the strCR and strLF


 

Re: A Constant ... Constant?

2005-01-24 09:09 • by Jeff S
This is the most pathetic thread of comments I've ever seen at this site.  What a great idea, Environment.NewLine() ??  or "\r\n"  ???   Brilliant!  Alex, you should have thought of these and mentioned them in your initial post! 

Re: A Constant ... Constant?

2005-01-24 11:01 • by phx

BTW


"\r\n"


2 bytes, not 4 ;)

Re: A Constant ... Constant?

2005-01-24 11:26 • by
28361 in reply to 28359
phx:

BTW


"\r\n"


2 bytes, not 4 ;)



Are you so sure those aren't Unicode characters?  [*-)]

Re: A Constant ... Constant?

2005-01-24 14:46 • by Blue
28365 in reply to 28357

Re: "This is the most pathetic thread of comments I've ever seen at this site.  What a great idea, Environment.NewLine() ??  or "\r\n"  ???   Brilliant!  Alex, you should have thought of these and mentioned them in your initial post! "


As opposed to the chock-full-o-content post you just made?


Oops, I just did it too! [:P]


 

Re: A Constant ... Constant?

2005-01-24 20:35 • by JamesCurran
28378 in reply to 28359

phx:
BTW
"\r\n"
2 bytes, not 4 ;)


ahem....


First of all, "\r\n" is three bytes, not two (don't forget the terminating NUL)


Second, the joke was the the original poster had written "/r/n" which really is four (well, five) bytes. Scroll back and finally have the laugh that the rest of us had a week ago.

Re: A Constant ... Constant?

2005-01-27 21:14 • by
28590 in reply to 28359
phx:

BTW


"\r\n"


2 bytes, not 4 ;)





Well.. if your talking about the internal memory representation of this
in .Net then it is 4 bytes with no null terminator when placed in a
string vairable.  If your talking about the byte size of this
piece of data as it gets written somewhere, this it is dependant on the
character encoding (ASCII, UTF8, UTF16, etc).





« PrevPage 1 | Page 2Next »

Add Comment