Artifacts Associated With Ticket 8cae59ecb03a6269
Ticket change [b51d2e2ea8] (rid 227994) by jan.nijtmans on 2024-06-20 07:57:20:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/x-fossil-wiki"
- comment initialized to:
There's a difference between "-encoding binary" and "-translation binary". The first one is simply an alias for "-encoding iso8859-1". The second one also sets -eofchar to {} and -transation to lf. This is a cause for confusion, even though it is [https://core.tcl-lang.org/tcl/artifact/f375dcda7952c356?ln=179-186|clearly documented]: Many people use "-encoding binary" while they really mean "-translation binary". An example is [85ddd247b6|this] ticket So, should we not simply remove "-encoding binary", or - even better - let it generate an error-message saying: "Please use -translation binary". - foundin initialized to: "9.0"
- is_private initialized to: "0"
- login: "jan.nijtmans"
- priority initialized to: "5 Medium"
- private_contact initialized to: "0c50e5320704d174412e57b873d8932de15303e0"
- resolution initialized to: "None"
- severity initialized to: "Minor"
- status initialized to: "Open"
- submitter initialized to: "jan.nijtmans"
- subsystem initialized to: "- New Builtin Commands"
- title initialized to:
Eliminate "-encoding binary" in favour of "-translation binary"
- type initialized to: "Bug"
Ticket change [7e51c47a02] (rid 227996) by oehhar on 2024-06-20 09:03:46:
- icomment:
Hi Jan, thank you for bringing this up. Yes, the confusion is endless. I see value in having "-encoding binary" to tell, that it is 1:1. And "-encoding 8859-1" sets an encoding. By chance, both are the same. But having different names for the same thing is also a challenge. I can live with "-encoding binary" is accepted and magically changed to "-encoding 8859-1". But this is not beautiful. I have no clear opinion on this. The magic on setting multiple things the same time (-translation, -eofchar, -encoding) is handy. Specially, I like "open $f b". This "suggestes" that there is a special binary mode. But this does not exist in the interface. There are 3 independent settings in this field. And having "-encoding 8859-1" for binary makes the whole story more complicated. Thank you, Harald
- login: "oehhar"
- mimetype: "text/x-fossil-wiki"
- username: "oehhar"
- icomment:
Ticket change [87e62c11a0] (rid 227997) by jan.nijtmans on 2024-06-20 09:50:08:
- icomment: "I will experiment with this"
- login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"
Ticket change [d325bba69c] (rid 227998) by apnadkarni on 2024-06-20 10:03:35:
- icomment:
I agree that current situation is confusing, and like Harald, have no clear opinion, just some thoughts. If we were starting from scratch, I would have liked to stick to the principle that setting one option should never silently change another option as -translation does today. If you want the low level options (eof, encoding, translation) that are required for binary mode, set them via fconfigure yourself, or use the simple "open b" method. However, changing -translation to not modify eof and encoding settings would now be too disruptive, so that's not an option. That leaves the question of what to do about -encoding binary. Leaving it in the current state means - `fconfigure $chan -encoding` returns a different value (iso8859-1) from what was set (binary). This gives me a bit of discomfort. - This is a (small) incompatibility with Tcl 8. If changed as Jan suggests, - It is consistent in that there is really no encoding called "binary" and there is no question of fconfigure returning a different value than was set. - This is also incompatible with Tcl 8, though in a different, probably more common and therefore serious, manner than above. A third option, not necessarily one I favor, but throwing it out there, is to make `-encoding binary` a synonym for `-translation binary` so it would also change eof and line-ending settings. - This in theory is the most incompatible with 8.6 but could actually most compatible in practice. Code that is using it will likely be also changing eof and line-endings and if not, should have been doing so and is probably broken code that would be fixed. The second option (Jan's) seems cleanest but my gut feel is that the first and third options will cause the fewest compatibility problems. With the second option, correct code "fconfigure $chan -encoding binary -translation lf -eofchar {}" will now fail. So...mixed feelings and not very helpful comments! If I were really pushed, I would keep things as they are (with a release note) but only because at this particular moment I lean towards compatibility over cleanliness :-) - login: "apnadkarni"
- mimetype: "text/x-markdown"
- icomment:
Ticket change [afe5a182f6] (rid 227999) by sebres on 2024-06-20 10:58:15:
- icomment:
There is indeed no encoding binary, but the channel may be binary, so why still not consider it like in 8.x as binary encoding? And a setting this via translation is a bit different to me: it'd also change `eofchar` and `translation`, what is correct for pure binary mode of channel, however if one uses something like: ``` chan configure -encoding binary -eofchar {} ``` the expectation is rather that `translation` remains `{auto crlf}` or `{auto lf}` **depending on platform.** So why not just "revert" back to the 8.x handling for consistency and just accept pseudo encoding name `binary` for binary mode retaining translation as it is? Let alone iso8859-1 is never comparable with binary mode, because one prefers strings another bytearrays (and for example strictly seen iso8859-1 has to reject all chars 0x00-0x1F and 0x7F-0x0F), so it is still more confused then (and previous handling of 8.x. remaining binary as value is more consistent). Why having an artificial encoding name (what is not really an encoding just a mark for bytearray handling) is so bad? Take a look at `unicode` - it is also not existing encoding, but just a mark for unicode handling, nothing else. But the name is pretty usable. <blockquote>> Many people use "-encoding binary" while they really mean "-translation binary".</blockquote> This is not an argument in my opinion: 1. RTFM 2. In case of "backwards compatibility vs. theoretical possibility for typo" we shall always prefer the first, because... 3. If one would consider arguments like that, then let us forbid everything what can introduce a confusion (hardly possible in a script-lang, especially in that with EIAS model) and ignore every compat question in the future. So I'd just switch back to 8.x handling: `binary` is valid value that can be set with `-encoding` parameter similar to `unicode` (which is also unknown encoding, rather a sign we'll work internally with unicode string instead). But as already said, I'd really use `binary` as return value (instead of iso8859-1)... again, similar to 8.x, to unicode pseudo encoding, and pretty backwards compatible. - login: "sebres"
- mimetype: "text/x-markdown"
- icomment:
Ticket change [8aa0ef51c3] (rid 228000) by oehhar on 2024-06-20 11:35:50:
- icomment:
I agree with Sergey. The visual beauty of "-encoding binary" is great. Thank you, Harald
- login: "oehhar"
- mimetype: "text/x-fossil-wiki"
- username: "oehhar"
- icomment:
Ticket change [02bc18dcc1] (rid 228001) by cjmcdonald on 2024-06-20 13:21:27:
- icomment:
As the submitter of the ticket which Jan referred to, I'll comment that there was no confusion between "-encoding binary" and "-translation binary". I'm aware of the difference, and would normally use "-translation binary" in a program, but chose to use "-encoding binary" in the ticket because I thought that it more clearly demonstrated the issue, which is that setting encoding to binary results in it showing an encoding of iso8859-1. That is what is confusing. Using "-translation binary" doesn't make any difference, it still results in a channel encoding of iso8859-1, in Tcl 9.0b2, whereas in 8.x it showed a binary encoding. The description which Jan linked to as "clearly documenting" the behaviour simply says that the encoding should be set to binary, preferably using "-translation binary". It says nothing about that encoding setting being silently changed to iso8859-1. As far as I can see that's undocumented in the man pages, and is really exposing some artefact of the internal implementation to the user. I wasn't aware that "-encoding binary" is an alias for "-encoding iso8859-1". I observe that one of the goals of very recent commits on Tk widgets was to keep size values specified on options unchanged, as specified by the user, rather than changing them to the internal pixel value - that was considered bad practice, and this seems to me to be a similar case.
- login: "cjmcdonald"
- mimetype: "text/plain"
- icomment:
Ticket change [d48ec7d629] (rid 228002) by jan.nijtmans on 2024-06-20 13:42:19:
- icomment:
<pre> > I observe that one of the goals of very recent commits on Tk widgets was to > keep size values specified on options unchanged, as specified by the user, > rather than changing them to the internal pixel value - that was considered > bad practice, and this seems to me to be a similar case. </pre> Indeed, that's why I'm surprised that in Tcl 8.x: <pre> % fconfigure $f -translation binary % fconfigure $f -translation lf <\pre> I would expect "-translation" to give back "binary" in stead of "lf" here, then that can be used to check for binary mode. - login: "jan.nijtmans"
- mimetype: "text/plain"
- icomment:
Ticket change [dfc5fd5ee8] (rid 228003) by sebres on 2024-06-20 14:13:34:
- icomment:
<blockquote>> I would expect "-translation" to give back "binary" in stead of "lf" here, then that can be used to check for binary mode.</blockquote> Huh, so you'd expect still one additional backwards incompatibility in 9.0? "-translation binary" did never set itself to "binary", it was solely a setter for grouped setting <code>-encoding binary -translation lf -eofchar {}</code>. Nothing else. I don't think Tcl really needs a change like that. - login: "sebres"
- mimetype: "text/x-markdown"
- icomment:
Ticket change [677d287494] (rid 228023) by apnadkarni on 2024-06-21 03:37:52:
- icomment:
@sebres regarding "why not just "revert" back to the 8.x handling for consistency", see [85ddd247b6]. Though I do not myself understand why fixing that bug required the change in what fconfigure -encoding returned.
- login: "apnadkarni"
- mimetype: "text/x-fossil-plain"
- icomment:
Ticket change [2117006f18] (rid 228034) by jan.nijtmans on 2024-06-21 08:15:24:
- assignee changed to: "jan.nijtmans"
- icomment:
I see the discussion going into two directions. One is about the [85ddd247b6|introspection], one is about "binary" being an alias for "iso8859-1". I just discovered, "iso8859-1" has two aliases already: the empty string and "binary". It was already like that in Tcl 8.6: <pre> $ tclsh8.6 % set f [open file.txt w] file3 % fconfigure $f -blocking 1 -buffering full -buffersize 4096 -encoding utf-8 -eofchar {} -translation auto $ fconfigure $f -encoding {} $ fconfigure $f -blocking 1 -buffering full -buffersize 4096 -encoding binary -eofchar {} -translation auto </pre> Let's handle this in this ticket - login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"
Ticket change [fcc8661d83] (rid 228379) by jan.nijtmans on 2024-07-01 21:20:36:
- closedate changed to: "2460493.38930764"
- closer changed to: "jan.nijtmans"
- icomment:
TIP #699 is accepted now, there's no "-encoding binary" any more. @sebres suggested to change "-encoding binary" to function the same as "-translation binary": setting the -translation to lf and -eofchar to {} at the same time. The problem I see with this suggestion is that extensions can silently break. The follwing use-case: A channel is being read. In the middle, something happens (like an encoding error). The application wants to see what happens, so the -encoding is changed to "binary" (while the original encoding is stored in a variable). A few more bytes are read. Then the encoding is restored. If we follow @sebres' suggestion, setting -encoding to "binary" will also set the -eofchar and -translation. If the channel was in crlf translation mode, then it won't be restored any more: the resulting translation is changed to lf. The current solution in TIP #699 means that the code needs to change: You can no longer set a channel to -encoding "binary", just use -encoding iso8859-1 in stead (which does exactly the same here). Hope this helps - login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"
- resolution changed to: "Fixed"
- status changed to: "Closed"
Ticket change [98b0ff282a] (rid 228381) by sebres on 2024-07-01 21:44:17:
- closedate changed to: "2460493.40576346"
- closer changed to: "sebres"
- icomment:
<blockquote>> If we follow @sebres' suggestion, setting -encoding to "binary" will also set the -eofchar and -translation. If the channel was in crlf translation mode, then it won't be restored any more: the resulting translation is changed to lf.</blockquote> So you (TCT) have decided to break it completely instead (since there will be no -encoding binary anymore). Well thought out!<br/> If you try to justify your decisions with arguments like that, please think firstly few minutes about (or still better send your thoughts to the TIP discussion in the time the votes have not yet taken place).
- login: "sebres"
- mimetype: "text/x-markdown"