I've decided, in effort to do more studying, to begin writing tutorial-ish type documents.. hopefully we'll all learn something from it.

For reasons I'm sure some of you are very aware of, I'm going to start with the humble NewLine.
Also known as Environment.NewLine.

New Line at it's core is a string structure built to return certain characters depending upon your operating system. In most cases with C#, whether or not your using a windows or unix deployment.
The characters it returns are known as 'Feed Line' and 'Carriage Return' ("\n" and "\r").

These two characters are used in unison to first create a new line under the current (feed line) and then update your windows form so that it displays the most recently entered text (carriage return).

++ I should clarify that it does this by representing a unicode string that your machine interprets.

Now as software developers it should always be an end goal to be as efficient as possible. This is called the process of optimization and it usually happens last, after the game mechanics actually work. So the question becomes: What do you finalize as during the optimization process?

The answer is it completely depends what you're working on. While I've had numerous people disagree, I will provide for you a documented and fact-based argument. Please consider:

In the UO client when you produce a message to a player, it appears on the bottom left hand corner of their game window, and each subsequent message pushes them upwards. There are also no other instances in which runUO or UO requires a Carriage Return. There is also no need to worry about "platform specific" issues because Unix also does not innately call Carriage Return through the use of Environment.NewLine. That being said, you're not only calling CR for no reason, you're making making multiple calculations to provide the exact same string value that \n produces (\u000A). It is for these reasons, in the case of UO Emulation, I would argue NewLine is not only pointless, but a burden.

Code:
        public static String NewLine {
            get {
                Contract.Ensures(Contract.Result<String>() != null);
#if !PLATFORM_UNIX
                return "\r\n";
#else
                return "\n";
#endif // !PLATFORM_UNIX
            }
        }

Source: http://referencesource.microsoft.com/#mscorlib/system/environment.cs
 
Last edited:
Back