Skip to content

Conversation

denis-sh
Copy link
Contributor

@denis-sh denis-sh commented Sep 8, 2012

  • Refactor std.stdio.File
  • Fix Issue 7659 - std.stdio.File.close() erases file.name
  • Fix std.stdio.File part of Issue 4624

@alexrp
Copy link
Contributor

alexrp commented Sep 8, 2012

  • 392b3e76083bb8a4b18130d0d7f337c6a255cee6: LGTM.
  • 8db9b54706bc5e91707eb6a849db4708aa58a78e: See comments.
  • c5c171a9e4126dfdca04223b93143f4185b5c434: LGTM.

@alexrp
Copy link
Contributor

alexrp commented Sep 8, 2012

By the way, you may want to add yourself to the authors list.

@denis-sh
Copy link
Contributor Author

denis-sh commented Sep 8, 2012

"If" and 2x"that the" are fixed.
"" is now retured instead of null.

@denis-sh
Copy link
Contributor Author

denis-sh commented Sep 8, 2012

Why is this an assert? Did you mean to comment this out?

Can't find that comment... what line?

@alexrp
Copy link
Contributor

alexrp commented Sep 8, 2012

Sorry, something went awry with that comment. I was asking why the assert in the name property is necessary.

@denis-sh
Copy link
Contributor Author

denis-sh commented Sep 8, 2012

Sorry, something went awry with that comment.

And it looks like it was 2 "if" comments but I have seen only one...

I was asking why the assert in the name property is necessary.

Just for tracking possible bugs in File implementation (e.g freed and overrited Impl).

P.S.

Damn Github doesn't show any of your old comments now and doesn't send line numbers in email notifications!

@alexrp
Copy link
Contributor

alexrp commented Sep 8, 2012

And it looks like it was 2 "if" comments but I have seen only one...

Yeah, I thought the first one got lost, so I commented again. But it's OK, you've fixed all the issues I pointed out.

Just for tracking possible bugs in File implementation (e.g freed and overrited Impl).

So I presume that people using the name property don't have to fulfill that assert?

@denis-sh
Copy link
Contributor Author

denis-sh commented Sep 8, 2012

Just for tracking possible bugs in File implementation (e.g freed and overrited Impl).

So I presume that people using the name property don't have to fulfill that assert?

No they don't. The problem is in absence unified way to mark:

  • this tricks when our library is used incorrectly (asserss or Exceptions are used, but only asserss are acceptable IMHO);
  • this tricks when it's used correctly (only Exceptions are used, the most unified part);
  • this tricks when it is our bug in library (only asserss should be used, not sure where are examples).

@alexrp
Copy link
Contributor

alexrp commented Sep 8, 2012

LGTM then.

@denis-sh
Copy link
Contributor Author

denis-sh commented Sep 8, 2012

LGTM then.

Sorry, one more commit. )

@alexrp
Copy link
Contributor

alexrp commented Sep 8, 2012

Looks OK too.

@denis-sh
Copy link
Contributor Author

Added 2 more commits to make std.stdio.File finally usable for non-Windows users (only non-Windows because of blocked by snn.lib Issue 7648 and nasty Issue 7033).

@alexrp
Copy link
Contributor

alexrp commented Sep 12, 2012

  • 5cf41e8d1e25ca639fd1376a941c906412b67bc5: Looks reasonable, but are you sure this won't break code?
  • d46d2e36159b38d5b08a91641d7e249bd9e6059b: LGTM.

@denis-sh
Copy link
Contributor Author

5cf41e8d1e25ca639fd1376a941c906412b67bc5: Looks reasonable, but are you sure this won't break code?

It will. Just like any other incorrect behavior bugfix it will break the code relying on that. I just hope there is no (little) such code because personally I can't imagine me writing code that rely on undocumented fflush call in a function that never ever should call fflush.

@andralex
Copy link
Member

Why is this failing?

@denis-sh
Copy link
Contributor Author

Why is this failing?

You mean autotester, yes? As you see test dmd fails because runnable/statictor.d postscript sees empty output instead of this 8 lines...

Sorry, I have no idea (except another dmd bug) too. Will try to dig into.

@denis-sh
Copy link
Contributor Author

OK. 5cf41e8d1e25ca639fd1376a941c906412b67bc5 breaks the code relying on write[f]ln flushing behavior. And test/d_do_test.d contains such code. Really sad. It passes on Windows because rawWrite flushes.

@braddr, is it a bug or do you really rely on this?

@denis-sh
Copy link
Contributor Author

OK. It's clearly a bug. The test will fail once flush will be here at line 406 because postscript doesn't expect "Executing ..." message.

@denis-sh
Copy link
Contributor Author

(I meant possibility of random failures)

@denis-sh
Copy link
Contributor Author

Will try to fix this in dmd pull 1124.

@denis-sh
Copy link
Contributor Author

Fixed. Have to wait for revising/merging dmd pull 1124.

}
private Impl * p;
private Impl* p;
private string m_name;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't use the m_ convention anywhere. Either use name or use _name. In the latter case you'll need to also change p with _p.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, why migrating the name outside of Impl?

@andralex
Copy link
Member

Some refactorings eliminating old bug workarounds are great (e.g. write*, various opens). I have a few nits with others as noted.

@denis-sh
Copy link
Contributor Author

denis-sh commented Oct 4, 2012

To @andralex (rebased with the fallowing cosmetic fixes):

we don't use the m_ convention anywhere...

Renamed m_name to _name, p to _p.


not worth distinguishing between null and ""

Distinguishing removed. It was incorporated because of @alexrp comment:

I think this is a bit unfriendly, in terms of usability. Returning an empty string when no name is available seems better.


This leads to bad alignment. If there are two branches to an if, both should be either inline or on next line.

Alignment fixed.

@denis-sh
Copy link
Contributor Author

denis-sh commented Oct 4, 2012

Also, why migrating the name outside of Impl?

A copy of p.name in File is required to fix Issue 7659 and prepare to fixing part of Issue 4624.

@denis-sh
Copy link
Contributor Author

denis-sh commented Oct 4, 2012

This was intentional. Why remove it?

How interesting. Does it mean that it was intentional for std.stdio.File.writefln but not for std.stdio.File.writeln as I see no complains about the latter? Probably it doesn't and you are against entire Fix Issue 8219 - File.writeln is slow commit: 870bb84c21a20cab817cb69a54d26a16e553cb05.
My opinion is in commit description and in Comment 1 of Issue 8219.

And I'd like to see your explanation why it was added. Because it is undocumented, useless (see my opinion in commit description), inconsistent with IO in other languages, and even inconsistent with std.stdio.writeln. So it is obviously and completely unexpected performance and USB flash drive killer (now it is also SSD killer).

There is absolutely no need to explicitly flush a stream on new line because it is expected only for console output which is line buffered or unbuffered by default.
* don't throw AssertError in writef
* make these functions consistent with std.format.formattedWrite
@andralex
Copy link
Member

andralex commented Oct 4, 2012

This was intentional. Why remove it?

How interesting. Does it mean that it was intentional for std.stdio.File.writefln but not for std.stdio.File.writeln as I see no complains about the latter? Probably it doesn't and you are against entire Fix Issue 8219 - File.writeln is slow commit: 870bb84.
My opinion is in commit description and in Comment 1 of Issue 8219.

And I'd like to see your explanation why it was added. Because it is undocumented, useless (see my opinion in commit description), inconsistent with IO in other languages, and even inconsistent with std.stdio.writeln. So it is obviously and completely unexpected performance and USB flash drive killer (now it is also SSD killer).

First of all, let's not forget (a) nobody is after you; (b) to the extent we're less competent than you think you are, it's not our fault; (c) we're all in this together as we want to do good things and move the state of the art forward.

The intent behind adding flush to writeln and writefln was simple - to make for more of a difference from write(..., '\n') and to behave unsurprisingly on block-buffered streams. So one would use writeln to get a buffered line, and write(..., '\n') to get an unbuffered one (on a block-buffered thing).

Anyhow, it seems this strategy is too obscure, so I'm fine with removing the flush. I'll make one more pass now through the latest. Keep in mind - we're on the same boat and we want to do Good Things(tm). Thanks.

andralex added a commit that referenced this pull request Oct 4, 2012
@andralex andralex merged commit ad87f38 into dlang:master Oct 4, 2012
@andralex
Copy link
Member

andralex commented Oct 4, 2012

merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants