-
Notifications
You must be signed in to change notification settings - Fork 323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Text.write
Function
#3518
Add Text.write
Function
#3518
Conversation
e89edde
to
7988555
Compare
@@ -14,6 +14,7 @@ from Standard.Base.Data.Text.Encoding as Encoding_Module import Encoding, Encodi | |||
from Standard.Base.Error.Problem_Behavior as Problem_Behavior_Module import Problem_Behavior, Report_Warning | |||
import Standard.Base.Data.Locale | |||
import Standard.Base.Meta | |||
import Standard.Base.System.File.Existing_File_Behavior |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Importing something from Standard.Base.System.File
seems to create a direct link from core strata of the language (as Text
is one of the core types) towards much less important strata - e.g. I/O subsystem. I believe this goes against principles of modularity. I believe the language and core libraries shall be as small as possible, but modularly extensible - be it Java or Enso.
This decay of mutual dependencies between different stratas of StdLib is hard to prevent, when we don't have tools to ensure compile time failures when a core strata attempts to call higher level strata. However that doesn't mean we should encourage such dependencies. Having reference to File
in Text.enso
is an example of such strata crossing dependency and I'd suggest to avoid it.
I know where it leads (see The Entropy of Software page 60, Practical API Design Confessions of a Java Framework Architect book). I've been there at least twice. With NetBeans and with Java. We end up with (this time not object but) functionally oriented spaghetti code and it is going to be hard to fix the mutual dependencies in future.
I guess the primary motivation for having Text.write
is usability. Our users are more likely to find the method on existing Text
object than some static function in some other library. Such a desire goes against the modularization effort. Huge problem when designing Java APIs, but other modern languages have an answer to that: extension functions.
Doesn't Enso also supports extending other types with new functions/methods? Then the write
function should be defined by File.enso
, but register itself as an extension into Text
type.
If possible, I'd find it way better design from modularity perspective.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm kind of inclined to agree that we are heading towards a spaghetti monster but at the same time PR implements what the ticket asked for
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy to move it to File
if we decide that's the right approach.
Reg. extension functions - we have those yes, so I can rely on it. But I'm not sure if the language spec 1.0 includes them - IIRC they are removed so the situation may complicate a bit. Maybe we will be able to emulate the desired behaviour with a typeclass.
So I can move the definition to File.enso
- question is - depending on the language spec, if we may need to move it back here. But since this is a small operation, I think it is ok to do so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JaroslavTulach That's a very good argument. Our stdlib is a little bit spaghetti because of lack of refactoring (which should be done in the meantime when implementing tasks) and also because of lack of proper tools to resolve it. It was one of the reasons why we are making changes to the language design. Currently, you don't have the tools in the language to resolve SOME of such a convoluted designs. In the past, we were thinking that we can introduce type classes to the language later in the future, but we realized that lack of them is very harmful right now - your comment shows one of such harmful behaviors The new lang design allows for making it nicer. We will fix the lang and then fix the libraries. On Monday the doc will be ready for reading, I'll ping you guys and I'd love to hear feedback about it from the perspective of this issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've implemented it as an extension within File.enso
. Once we have the design doc agreed we should do a sanity pass and make sure all is how we want it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would probably favour File.wrtie_text text
instead of Text.write file
as well
@@ -89,6 +90,10 @@ public void delete() throws IOException { | |||
truffleFile.delete(); | |||
} | |||
|
|||
public void move(EnsoFile target, CopyOption... options) throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would probably benefit from #3471 which is the final stages of being merged
distribution/lib/Standard/Base/0.0.0-dev/src/System/File/Existing_File_Behavior.enso
Show resolved
Hide resolved
7988555
to
17cbe4d
Compare
We discussed I think we may find we want to add |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. Defining Text.write
in File.enso
looks way nicer from an architecture perspective.
Pull Request Description
Implements https://www.pivotaltracker.com/story/show/182309026
Important Notes
Checklist
Please include the following checklist in your PR:
Scala,
Java,
and
Rust
style guides.
./run ide dist
and./run ide watch
.