Worst ideas/features in programming languages?

Jacob Carlborg doob at me.com
Wed Oct 13 19:55:29 UTC 2021


On Monday, 11 October 2021 at 15:59:10 UTC, Atila Neves wrote:

> * Worst features implemented in a non-toy language

I can't believe no one has mentioned this yet: PHP register 
globals. That is, the feature that creates variables in your 
scripts from request parameters.

> * Worst features (in your opinion) in D

Difficult to say, but all the half implemented features.

> * Features you'd like to see in D

* Non nullable pointers and reference types by default

* Built-in or syntax sugar for optional types

* Native tuples with destruction and named values:

     ```d
     (int, string) tup = (1, "foo");
     auto (a, b) = tup;

     (int, int) point = (x: 2, y: 4);
     auto x = point.x + a;
     ```

* Some form of zero overhead exceptions. Example:

     ```d
     struct PermissionDenied {}
     struct FileNotFound {}

     int open(string filename) throw(PermissionDenied, 
FileNotFound);

     string readFile(string filename) throw(auto)
     {
         auto fd = open(filename);
         // ...
     }

     void main()
     {
         try
             auto content = readFile("foo.txt");
         catch (PermissionDenied e) {}
         catch (FileNotFound e) {}
     }
     ```

     The above is lowered to:

     ```d
     struct PermissionDenied {}
     struct FileNotFound {}

     Result!(int, PermissionDenied, FileNotFound) open(string 
filename);

     Result!(string, PermissionDenied, FileNotFound) 
readFile(string filename)
     {
         R0 __tmp0 = open(filename);
         int fd = void;
         switch (__tmp0.tag)
         {
             case R0.Tag.success:
                 fd = __tmp0.value;
             // ...
             break;

             case R0.Tag.error0: return 
typeof(return)(__tmp0.error0);
             case R0.Tag.error1: return 
typeof(return)(__tmp0.error1);
         }
     }

     void main()
     {
         R0 __tmp0 = readFile("foo.txt");
         string content = void;
         switch (__tmp0.tag)
         {
             case R0.Tag.success:
                 content = __tmp0.value;
                 break;

             case R0.Tag.error0:
                 PermissionDenied e = __tmp0.error0;
                 break;

             case R0.Tag.error1:
                 FileNotFound e = __tmp0.error1;
                 break;
         }
     }
     ```



--
/Jacob Carlborg



More information about the Digitalmars-d mailing list