4 ms·
someString.append(System.getProperty("line.separator")); vs some_string += "\n" Edit: Someone's in disagreement with me, so I'll try and clarify. I'd cla
by cubicle67 15y ago
someString.append(System.getProperty("line.separator"));
vs
some_string += "\n"
Edit: Someone's in disagreement with me, so I'll try and clarify. I'd classify boring code as code where the intent gets lost in the syntax/language or other constructs the maintainer of the code doesn't care about but are required anyway.
Trying to open and read a file in Java is probably a better example as the intent (open this file and read the contents) is buried in about 6 lines of boilerplate code
I use Java as an example because in a previous life I used to write it and see this as perfectly acceptable
- dextorious 15y agoWell, for one you can probably make your own "+=" for strings, if not available, since Dart has operator overloading. Also, System.getProperty("line.separator") does not translate to n"\n". The first makes your program more portable. Of course it could be made accesible easier, eg as a constant System.NEWLINE or something. [UPDATE] Downvote? Really? Because someone thinks "\n" is the same as "line.separator"?
- nmcfarl 15y agoOf course they could have taken perl's tact and defined "\n" to mean System.NEWLINE not 0x0A. That would have been an improvement right there.
- jeltz 15y agoIndeed they do not translate into the same thing. But neither makes your program more or less portable in itself. It all depends on what you want to use it for. Some files and protocols should always have \n some always \r\n while in some cases it should be the system line separator. I think Python, Perl, C, and Ruby have fixed that quite well by making the IO library do the conversions. I do not remember if it is the same in Java.
- d0mine 15y agoI didn't downvote, but see universal newline support in Python http://www.python.org/dev/peps/pep-0278/ http://www.python.org/dev/peps/pep-0278/