- cross-posted to:
- [email protected]
- cross-posted to:
- [email protected]
Just
puts(“I’m a teapot”);
:)Maybe c# has similar. There’s \r\n or \n like c++ and Environment.NewLine.
Probably it’s similar in that Environment.NewLine takes into account the operating system in use and I wonder if endl in c++ does the same thing?
C# also has verbatim strings, in which you can just put a literal newline.
string foo = @"This string has a line break!";
As long as it doesn’t end in ;
No debate, std::endl can be a disaster on some platforms due to flushing crap all the time.
Just because the box says something is flushable doesn’t mean you should flush it.
It’s a very C++ thing that the language developers saw the clusterfuck that is stream flushing on the kernel and decided that the right course of action was to create another fucking layer of hidden inconsistent flushing.
programmers manage to do stupid shit in every language. i was wondering if there was a way to stop them, and golang comes close but maybe proves it can’t be done. idk!
I hear C++ was greatly inspired by the fifth circle of hell.
Considering std::cout should only directly be used when you are too lazy to place breakpoints, I totally get the decision to auto-flush.
Fuck endl, all my homies hate endl
bloods 4 lyfe
Cout << “\n”; is dumb and you should feel bad
You’re right, that is incredibly dumb. Just not for the reasons you think it is. Imagine using iostream rather than stdio and unironically trying to clown on \n
Is this not a debate for freshman students and other assorted opinionated know-nothings? Or just people shitposting.
My mistake. You think it’s srs.
(And your opinion is still bad)
Oh no! Did I hurt your feelings by clapping back when you insulted me on a shitpost comment chain? Your lack of self awareness is astounding
🙄
Feel this is relevant https://www.youtube.com/watch?v=IkpZggx4yNI
If
endl
is a function call and/or macro that magically knows the right line ending for whatever ultimately stores or reads the output stream, then, ugly though it is,endl
is the right thing to use.If a language or compiler automatically “do(es) the right thing” with
\n
as well, then check your local style guide. Is this your code? Do what you will. Is this for your company? Better to check what’s acceptable.If you want to guarantee a Unix line ending use
\012
instead. Or\cJ
if your language is sufficiently warped.It’s a “stream manipulator” function that not only generates a new line, it also flushes the stream.
Ah don’t worry, if you do
fopen(file, "w")
on Windows and forget to use"wb"
flag, it will automatically replace all your\n
with\r\n
when you dofwrite
, then you will try to debug for half a day your corrupted jpeg file, which totally never happened to me because I’m an experienced C++ developer who can never make such a novice mistake.
Doesn’t endl predate C++?
It’s not in C, if that’s what you mean.
fprintf(stdout, "%c", '\012');
deleted by creator
Wasn’t this {fmt} library merged into STL now? Does this solve this issue?
Anyways, there was also a constant that is the OS line ending without a flush, right?
C++ style text streams are bad and a dead-end design and
'\n'
.std::cout << "\nwhy not both" << std::endl;
In PHP it exists as well. I try to use PHP_EOL but when I’m lazy I simply do “\n”.
For me the answer is “Building backend applications with it instead of CLI applications, like Lerdorf intended.”
But also
"\n"
because it’s easier andPHP_EOL
is just an alias for"\n"
; it’s not even platform-dependent.PHP_EOL depends on your host system, it’s
\r\n
on Windows.I don’t really want to use what Lerdorf intended, PHP <= 4 was horrible, 5.x was mainly getting slowly rid of nonsense and with 7.x PHP started its slow path of redemption and entered its modern era.
While Lerdorf’s vision was great at that time for its intended use case, I wouldn’t want to build anything serious in it.
It actually outputs
"\n"
on a Windows system, but modern Windows to recognise that as enough of a newline, nowadays.I don’t really want to use what Lerdorf intended, PHP <= 4 was horrible
Actually a great point!
I am very sorry to remind everyone about the existence of Visual Basic, but it has:
- VbCrLf
- VbNewLine
- ControlChars.CrLf
- ControlChars.NewLine
- Environment.NewLine
- Chr(13) & Chr(10)
And I know what you’re asking: Yes, of course all of them have subtly different behavior, and some of them only work in VB.NET and not in classic VB or VBA.
The only thing you can rely on is that “\r\n” doesn’t work.
Apology not accepted, fuck you for reminding me!
great reminder to avoid microsoft products as much as i can
print('string\n', end='')
I just learned that in Python, it’s fucking terrible. Python is a fucking mess and my next script will be in a different language.
As a python lover, I have to ask, what don’t you like about it and what languages do you generally prefer?
I prefer strongly typed languages. Using bytes isn’t intuitive.
Transforming certain data types into other data types is often not straightforward.
The identation is the worst though. Let me format the code however I want.
python is a bad joke that never ends
Perhaps TS is not a terrible language for shell scripts after all
Never tried it, but I will probably be more at home than python.