r/ProgrammingLanguages • • Sep 21 '26

Discussion What’s one thing you wish more programming languages had?

If you could add one feature, behavior, or design choice to a programming language, what would it be?

It can be anything: syntax, type-system features, memory management, compiler behavior, tooling, error handling, performance-related features, or something completely different.

I'm especially curious about things you’ve wanted while actually programming but rarely see languages implement well.

Please keep the ideas reasonably practical and something that could realistically be implemented in a programming language.

56 Upvotes

299 comments sorted by

View all comments

Show parent comment

34

u/munificent Sep 21 '26

I designed this feature. :) There are three supported constructs.

  • You can use if for branching, with or without an else clause:

      var arguments = [
        if (debug) '--debug' else '--profile',
        if (verbose) '--verbose',
      ];
  • You can use for loops to repeat:

      var arguments = [
        for (var file in files) '--file=$file'
      ];
  • You can use ... ("spread") to unpack another sequence in place:

      var otherOptions = ['--enable-asserts', '--sandbox'];
      var arguments = [
        ...otherOptions
      ];

These can all be combined and nested arbitrarily. So an if isn't simply like a ternary operator because the branches can themselves contain further control flow and not just expressions:

var arguments = [
  for (var directory in directories)
    for (var file in directory.files)
      if (file.exists) ...['--file', file.path]
];

Also, this all works with set and map literals too.

5

u/fdwr Sep 22 '26

I designed this feature. :)

Thanks for not doing a Python, with its Yoda backwards if and for 🙃.

4

u/cmontella 🤖 mech-lang Sep 21 '26 edited Sep 21 '26

I don't know much Dart but this is very cool. It's like a form of logical indexing, which got me thinking how we'd do these in Mech, which supports logical indexing directly. The first one is like this:

options := ["--debug", "--profile", "--verbose"]
flags := [debug, ¬debug, verbose]
arguments := options[:, flags]

For loops we have just a broadcast operator:

arguments := ["--file=" + files]

For unpacking it's the base semantics:

otherOptions := ["--enable-asserts", "--sandbox"]
arguments := [otherOptions]

The last guy is trickier, we have to reach for a matrix comprehension:

arguments := [
  argument |
  directory <- directories,
  file <- directory.files,
  file.exists,
  argument <- ["--file", file.path]
]

so logical indexing isn't as powerful an abstraction as the control-flow-aware collection literals (is there a better name for this feature than that?), but I think it's still pretty flexible.

3

u/initial-algebra Sep 22 '26 edited Sep 22 '26

control-flow-aware collection literals (is there a better name for this feature than that?)

It's basically slightly different syntax for generators, you just don't need to write yield. Equivalently, they're monoid comprehensions.

1

u/RiceBroad4552 Sep 22 '26

This looks interesting.

For reference for others looking this up:

https://docs.mech-lang.org/

1

u/Clementsparrow Sep 21 '26 edited Sep 21 '26

nice. Can we also do something for cases like...

text : string = "some_prefix" +
#if DEBUG
    " DEBUG! " + debug_info() +
#end
    " some_suffix"

...beyond making a list and using a function like join on the list? Imagine an expression like this:

direction : Vec3 = (support
#if not NORMALIZED_SUPPORT
    / support.norm()
#end
    ).rotated(90°, rotation_axis)