News for hackers. Stuff that matters.
Re:What’s New in Python 3.8 by robocat on Monday October 14, 2019 @06:35PM (#21253592)

  def f(a, b, /, c, d, *, e, f):
Wow: IMHO that is a very ugly syntax to define a fn with 6 parameters, although it looks to be a path dependency on previous decisions (*, and CPython ,/) and clearly there was much discussion of the need for the functionality and the compromises: https://www.python.org/dev/peps/pep-0570/

It amazes me to see how certain features make it into languages via community/committee (octal numbers in JavaScript - arrgh!).

One thing I find really difficult to deal with in languages is the overloading of different syntactic(edit:semantic) usages of different symbols, which itself is a result of limiting ourselves to the ASCII symbols that can be typed. I don't recall written mathematics having the issue badly (although I haven't had to write any for a long time!).

Re:What’s New in Python 3.8 by chubot on Monday October 14, 2019 @06:53PM (#21253729)
Yes, "path dependence" is a good way to describe it. (And Python has been my favorite language for 16+ years now)

For https://www.oilshell.org/ , which has Python/JS-like functions, I chose to use Julia's function signature design, which is as expressive as Python's, but significantly simpler in both syntax and implementation:

Manual:

https://docs.julialang.org/en/v1/manual/functions/index.html...

Comparison:

https://medium.com/@Jernfrost/function-arguments-in-julia-an...

Basically they make positional vs. named and required vs. optional ORTHOGONAL dimensions. Python originally conflated the two things, and now they're teasing them apart with keyword-only and positional-only params.

A semicolon in the signature separates positional and named arguments. So you can have:

    func f(p1, p2=0, ...args ; n1, n2=0, ...kwargs)
So p2 is an optional positional argument, while n1 is a required named argument.

And then you don't need * and star star -- you can just use ... for both kinds of "splats". At the call site you only need ; if you're using a named arg / kwargs splat.

----

Aside from all the numeric use cases, which look great, Julia has a bunch of good ideas in dynamic language design.

The multiline strings in Julia appear to strip leading space in a way that's better than both Python multiline strings and here docs in shell.

Also Julia has had shell-like "f-strings" since day one (or at least version 1 which was pretty recent). Python has had at least 4 versions of string interpolation before they realized that shell got it right 40 years ago :)

Re:What’s New in Python 3.8 by chronial on Tuesday October 15, 2019 @06:46AM (#21257228)
But the Julia syntax can not represent arguments that can be passed either positional or named, right?
Re:What’s New in Python 3.8 by ddragon on Tuesday October 15, 2019 @11:40AM (#21259624)
Yes it can't, unless of course you just make two variables (one positional and one named) and inside the function you choose one.

Because of Julia's multiple dispatch paradigm, positional arguments are special compared to named arguments because they decide what method to dispatch to (in Julia f(x) is equivalent to x.f() in object oriented language, and it's extended to all positional arguments). That means that if you called f(a, b=nothing, c=nothing), f(1, c=1) it would dispatch to f(Int64, Nothing, Int64), while if you called f(a; b=nothing, c=nothing) with the same args it would dispatch to f(Int64). In Julia named arguments are effectively a way to pass more arguments without complicating the dispatch rules, and since there is only one way to call a function (outside of optional arguments, which appears to the end user as another implementation of a function) there is no ambiguity to where it dispatches to.

So basically, every language has it's own quirks, which the syntax decisions usually reflects, and Julia's scenario is fundamentally different from Python's.

Re:What’s New in Python 3.8 by chubot on Tuesday October 15, 2019 @01:09PM (#21260886)
Yeah that's true, but I consider it a feature and not a bug.

There was a rule in Google's style guide that said to only pass optional arguments with names, and required args without names. It basically enforced this separation while being slightly less flexible, because you can't have optional positional args or required named args.

Tens of millions of lines of code was written by thousands of programmers in that style, and it caused no problems at all. On the contrary it made code more consistent and readable.

Re:What’s New in Python 3.8 by bitcurious on Monday October 14, 2019 @06:48PM (#21253689)
I’d argue that written maths is worse with its overloading of the Greek alphabet. Although in the case of maths I’d argue that it’s a result of how slowly we write, with the programming equivalent usually being a variable name (autocompleteable).
Re:What’s New in Python 3.8 by eru on Tuesday October 15, 2019 @02:24AM (#21256006)
Yes, math is a much bigger culprit. Including for operator overloading.

Their saving grace is that humans are more intelligent interpreters.

If you ever try to translate a human-readable proof, even a fairly formal and rigorous one, into a computer proof assistant like Agda or Coq, you can see all the little ways humans cut corners.

Re:What’s New in Python 3.8 by BurningFrog on Monday October 14, 2019 @06:42PM (#21253644)
> which itself is a result of limiting ourselves to the ASCII symbols that can be typed

I think we're ready for programming languages using some visually good Unicode characters, instead of overloading `[]{}!@#$%^&*()-_/` for everything!

Re:What’s New in Python 3.8 by robocat on Monday October 14, 2019 @07:08PM (#21253846)
There are programming fonts that use ligatures to convert >= to ≥, or -> to →, so the source code remains in ASCII but symbol sequences show as unique Unicode characters.

A next step could be for common dev environments to actually convert symbol/key sequences to operators (how do APL programmers do it?)

Avoiding ambiguity and semantic overloading of ASCII symbols would surely help beginners (if also given a UI that clearly exposes ways to enter the new symbols). I always find one letter operators extremely strange too like u"word" s/foo/bar/ etc.

It seems a shame we can type in hundreds of Unicode symbols on a mobile virtual keyboard, but not readily on a physical keyboard.

JavaScript has supported Unicode for a long time, but the core language doesn't use it at all.

Re:What’s New in Python 3.8 by ken on Monday October 14, 2019 @11:22PM (#21255284)
> There are programming fonts that use ligatures to convert >= to ≥

It's a neat hack, but that's the opposite of what I want. It means I can't look at source code and know what characters make it up, which is the primary reason I'm still putting up with plain text files (and mostly ASCII) for source code at all.

Out of habit, I occasionally type some control-letter combination which is a valid command in Emacs, but in Xcode (and other native Mac apps) inserts an invisible character, which happens to be invalid in Swift. 10 minutes later, I get a compilation error pointing at a line of code that looks perfectly valid. Frustrating!

Re:What’s New in Python 3.8 by grincho on Monday October 14, 2019 @08:10PM (#21254269)
The Mac has provided easy access to symbols since 1984, with nice mnemonics like these:

    option-=  ≠
    option-<  ≤
    option->  ≥
    option-/  ÷
    option-o  ø
    option-w  ∑
I don't know why other OSes haven't adopted something similar. The first couple of these were even idiomatic in HyperCard's scripting language.
Re:What’s New in Python 3.8 by robocat on Monday October 14, 2019 @08:49PM (#21254490)
That's like visual puns, and is limited to whatever symbols seemed important to the developer at the time.

How do you discover how to type ß, °, «, ‡ etc?

Android's gboard uses phonetics (long press [s] key for ß), symbolic similarity (long press [*] key for ‡) and visual similarity (long press [<] key for «) which is guessable for some symbols, but isn't discoverable for others (you can search for emoji by name, but not symbols).

Re:What’s New in Python 3.8 by macintux on Monday October 14, 2019 @10:38PM (#21255111)
The Mac has had, as a standard feature for decades, an on-screen keyboard to allow you to explore the results of different key combinations. It’s a great tool.
Re:What’s New in Python 3.8 by macintux on Monday October 14, 2019 @10:41PM (#21255125)
I should note that, alongside it, is a useful search tool that allows you to find the character you’re looking for if you’d rather just search and don’t care to learn the key combination (if there is one).
Re:What’s New in Python 3.8 by cpach on Tuesday October 15, 2019 @04:12AM (#21256478)
Cool! Where do I find it?
Re:What’s New in Python 3.8 by macintux on Tuesday October 15, 2019 @09:22AM (#21258049)
In Mojave, and it’s pretty similar across versions IIRC: open keyboard preferences in system settings and check the “Show keyboard and emoji viewers in menu bar” box.

That will replace the language flag icon in your top bar with an odd icon with the command key embedded.

The second option in that menu is the keyboard viewer. You can show that and drag on a corner to make it as large as you want. Dynamically changes the keyboard as you hold down modifier keys.

Re:What’s New in Python 3.8 by kps on Monday October 14, 2019 @10:02PM (#21254926)
It's easy on the Mac to have a custom or purpose-built keyboard layout that makes sense for the user or context. It's a little harder with X (mostly due to uncoöperative DEs) but still doable.
Re:What’s New in Python 3.8 by kps on Tuesday October 15, 2019 @11:14AM (#21259287)
Self-reply for Kwpolska: Adding layouts to /usr/share/X11/xkb/symbols/ is straightforward (but is necessarily system-wide, and requires root), and I do that. However, for the popular desktop environments, it's like pulling teeth to have that layout treated as first-class with respect to switching and settings.

(On MacOS, putting a .layout file in ~/Library/Keyboard\ Layouts is enough.)

Re:What’s New in Python 3.8 by Kwpolska on Tuesday October 15, 2019 @02:28AM (#21256024)
I've hacked /usr/share/X11/xkb/symbols/xx files to have custom keyboard layouts, DEs are not able to mess with it.
Re:What’s New in Python 3.8 by kps on Monday October 14, 2019 @09:55PM (#21254880)
X has Compose, which originated slightly earlier (the key, that is, not the X11/xkb implementation), and is a tolerable alternative. e.g. [Compose / =] ↦ [≠]
Re:What’s New in Python 3.8 by thaumasiotes on Tuesday October 15, 2019 @01:42AM (#21255836)
> nice mnemonics like these:

> option-w ∑

This would grate on me every single time I had to use it. It's an S. Put it on option-s.

Re:What’s New in Python 3.8 by uranusjr on Tuesday October 15, 2019 @02:33AM (#21256044)
For context opt s is ß so the decision wouldn’t be easy if you want to include both.
Re:What’s New in Python 3.8 by thaumasiotes on Tuesday October 15, 2019 @01:48PM (#21261426)
What are á and à?

Putting double S on option-s just makes option-w for Sigma more grating. If they were going by shape, it'd be on option-b, which is equally stupid. But since it's on S, we can conclude that... someone at Apple knows German, but nobody can even name a Greek letter? That Germans are right and Greeks are wrong? What?

Re:What’s New in Python 3.8 by uranusjr on Tuesday October 15, 2019 @03:02PM (#21262365)
I don’t think it that extreme, but that German has higher precedence than Greek. If you need to include both characters, you have to pick one or the other, and for whatever reason this configuration happened. We might never know the true reason behind the decision, but stupility is unlikely the answer. Most seemingly stupid decisions (technical or otherwise) makes at least a certain amount of sense within its proper context, and it’s fair to talk down to it when you don’t have the risk of being judged by that decision.
Re:What’s New in Python 3.8 by thaumasiotes on Tuesday October 15, 2019 @03:37PM (#21262761)
I repeat:

> What are á and à?

The concept of variations on a common letter wasn't exactly new at the time. If you're supporting German and Greek, it seems safe to say you're also supporting French.

Re:What’s New in Python 3.8 by Kwpolska on Tuesday October 15, 2019 @02:31AM (#21256034)
Windows has a keyboard called US-International with extra symbols. Also, note that those key combinations might not exist in other keyboard layouts (replaced with local keys).
Re:What’s New in Python 3.8 by Razengan on Tuesday October 15, 2019 @09:27AM (#21258103)
I like to use characters like those as custom operators whenever I can. :)
Re:What’s New in Python 3.8 by Sean1708 on Tuesday October 15, 2019 @03:40AM (#21256344)
> I think we're ready for programming languages using some visually good Unicode characters

Some already do: https://docs.julialang.org/en/v1/base/math/#Base.:!=

Re:What’s New in Python 3.8 by amedvednikov on Monday October 14, 2019 @11:30PM (#21255316)
I'm experimenting with this in V [0]

  if a ≠ b {
is allowed along with

  if a != b {
vfmt (kinda like gofmt) will be able to convert != to ≠.

So far the response has been mixed.

Not everyone is open to this change.

[0] https://vlang.io

Re:What’s New in Python 3.8 by jfim on Monday October 14, 2019 @07:03PM (#21253803)
Many languages allow that. Scala allows characters in the math symbols (Sm) and other symbols (So) Unicode categories as identifiers for functions and variables, and APL has a rich notation that relies on many single character operators.
Re:What’s New in Python 3.8 by VVertigo on Monday October 14, 2019 @06:58PM (#21253759)
I’ve been looking at making up a second keyboard with a bunch of useful characters on it (similar to Tom Scott’s unicode keyboard) and learning Perl 6 to make use of it. I’m thinking that’s going to be my Winter Project/New Year’s resolution this year.
Re:What’s New in Python 3.8 by Pxtl on Monday October 14, 2019 @07:17PM (#21253917)
Oh god, this. I want a language that as I type, != Gets replaced with a proper ≠ not equals sign and proper symbols for AND, OR, and NOT.
Re:What’s New in Python 3.8 by roywiggins on Monday October 14, 2019 @10:29PM (#21255062)
Re:What’s New in Python 3.8 by gunn on Monday October 14, 2019 @10:31PM (#21255071)
Re:What’s New in Python 3.8 by codebje on Monday October 14, 2019 @08:37PM (#21254425)
Check out Lean Prover's online editor: https://leanprover.github.io/live/latest/

They borrow syntax from LaTeX math-mode to allow symbol entry, such that you can type "\ne" and as soon as you hit the space after the "e", you get ≠ instead.

The language plugin for Visual Studio Code does the same thing.

Lean Prover's not exactly a programming language, but :

    def foo (a b : ℕ) : ℕ → ℕ → ℕ :=
        λ a b, a + b
Still looks decent.

I think it has to be all or nothing though, since if it's optional the odds of getting decent editor support for it is low.

Re:What’s New in Python 3.8 by PeCaN on Monday October 14, 2019 @07:44PM (#21254096)
a lot of programming fonts have ligatures for this
Re:What’s New in Python 3.8 by jonnycomputer on Monday October 14, 2019 @07:56PM (#21254177)
What bothers me is that the / is separated by commas, which makes it seem like the signature is one more than it actually is (even if that is not the case technically). I haven't looked too carefully here though.
Re:What’s New in Python 3.8 by smitty1e on Monday October 14, 2019 @06:45PM (#21253665)
The point of that syntax is to offer more control for how functions, particularly in C-extensions, are invoked.

It will be a "good problem" to have the skillz to make this useful.