News for hackers. Stuff that matters.
Re:The Neat Programming Language by FeepingCreature on Monday December 25, 2023 @12:38PM (#38764431)
I too have made a language! Hope you find Neat interesting. It's heavily inspired by D, except with reference counting instead of garbage collector. Also, it has macros.

My DConf talk on the language is now up too! https://www.youtube.com/watch?v=nDqlYnS-K2c

Re:The Neat Programming Language by brabel on Monday December 25, 2023 @03:16PM (#38765722)
Haven't had the time to watch that talk yet... but what's your motivation to create a new language? Any drawbacks in D that you're trying to fix (besides the GC being replaced with RC - which many consider to also be GC by the way)?
Re:The Neat Programming Language by FeepingCreature on Monday December 25, 2023 @03:26PM (#38765805)
Yep, here's the big ones:

- proper macros

- proper sumtypes with implicit conversion

- more normal lambdas (seriously, D's lambdas are wild)

- faster compiler with more caching and (maybe) eventually live reload?

- proper packages instead of include path.

And a bunch of small fry like format strings and named parameters.

And yeah, um, GC can be good but the D GC kind of isn't. We use D at work, and we run into GC issues frequently. Neat's RC is a much thinner wrapper around C memory allocation, which is just better imo, much as GC and RC are logically equivalent in some ways.

Re:The Neat Programming Language by dataangel on Monday December 25, 2023 @04:08PM (#38766119)
For the uninitiated what are wild about D lambdas? I'm familiar with C++ lambdas and Python lambdas.
Re:The Neat Programming Language by FeepingCreature on Monday December 25, 2023 @04:26PM (#38766283)
Okay so if you're calling a D std.algorithm function, for instance

    int factor = 2;
    assert([2, 3].map!(a => a * factor).array == [4, 6]);
Then the `!` indicates that you're actually passing the lambda as a compiletime parameter to `map`. But the lambda can access the surrounding context! How does it pass a runtime value at compile time?

So what you're passing is actually purely a function symbol. The way that it gets the stack reference to the surrounding function is that it's actually a nested function. And the way that `map` gets the stack reference to pass to the lambda is that, effectively, that instance of `map` is also a nested function of the calling function.

That's also why you cannot pass a lambda as a template parameter to a class method in D: it already has a context parameter, ie. the class reference.

In Neat, the value of the lambda is the stackframe reference, and it's just passed as a regular parameter:

    int factor = 2;
    assert([2, 3].map(a => a * factor).array == [4, 6]);
Which avoids this whole issue at the cost of requiring some cleverness with refcounting.
Re:The Neat Programming Language by mhh__ on Monday December 25, 2023 @08:54PM (#38768257)
This "Just pass it as a name" pattern has a been a complete disaster for D IMO. It was before my time but I think the explanation for why seems to be annoyingly along the lines of "dmd optimizer likes it".

It also encourages people not to think about what the structure of their templates, so you can end up with truly massive amounts of duplication.

Re:The Neat Programming Language by FeepingCreature on Monday December 25, 2023 @09:13PM (#38768350)
Well, D lambdas and Neat lambdas cash out the same at the backend level. There shouldn't be a performance difference. If you're passing the context as an explicit parameter, that should turn out exactly the same as passing it as an implicit stackframe parameter. The difference is that instead of instantiating the template with the lambda, we're instantiating it with a type that uniquely corresponds to the lambda - it's pretty similar in the end.
Re:The Neat Programming Language by mhh__ on Tuesday December 26, 2023 @11:17AM (#38773041)
The original justification was probably that an alias works as a form of specialization.
Re:The Neat Programming Language by matheusmoreira on Monday December 25, 2023 @05:11PM (#38766635)
> proper packages instead of include path

Please elaborate on this. It's something I'm trying to get right in my own language since day one. I see in your language's manual that you have chosen to implement modules as files and packages as directories. I came up with something very similar but special cased the main module file so that the entire module could be contained in its directory.

  my-module/
    my-module.ln

  (import (my-module)); reads my-module/my-module.ln
How do you represent modules in your implementation? How do you handle module loading? What paths do you search? Do you support Linux distribution packaging? This last feature is something I'm interested in supporting, I added system directories to my search path for this reason but I wonder if there's anything else that I need to do.
Re:The Neat Programming Language by FeepingCreature on Monday December 25, 2023 @05:33PM (#38766880)
Yes-ish. Basically, it's sort of like D in the sense that a `module a.b.c;` always corresponds to a file `a/b/c.nt` somewhere. But the places where it looks follow a recursive hierarchy, not an include path: you can define paths to search, but you have to explicitly define import relations between those paths. And that's because it's not really a search path, it's a full-on package graph, where each package is only allowed to see imports from packages that it explicitly lists as a dependency. In D, if you're importing a Dub package, because it's just using a search path, the files from that Dub package can actually import modules from your main project. In Neat, the lookup order is "current package", then "dependency packages", then stop.

So Neat's actual hierarchy is "file [> folder]* > package", where `package` itself is optional in the import declaration: you can write `import package(gtk).gtk`, but you don't have to. This is occasionally useful during bootstrap builds when you want to clarify which version of the compiler an import is coming from: the current running compiler is always `package(compiler)`.

This is all because I've been writing it with something like a package manager in mind from essentially day one.

edit: I'm not looking at distribution packaging right now, because I'm not looking at non-source libs at all. That's something that can come later if it's needed at all.

Re:The Neat Programming Language by JonChesterfield on Monday December 25, 2023 @05:20PM (#38766739)
What do you mean by implicit conversion in the context of sum types? I don't see it under https://neat-lang.github.io/manual.html#types
Re:The Neat Programming Language by FeepingCreature on Monday December 25, 2023 @05:29PM (#38766829)
Oh yeah I didn't actually write this down in the manual: if you expect `(A | B)`, then both A and B implicitly convert to that type.
Re:The Neat Programming Language by JonChesterfield on Monday December 25, 2023 @05:53PM (#38767069)
Type A|B is implicitly constructible from A or from B sounds reasonable. A|A from A presumably an error, or possibly A|A itself is an error. Thanks
Re:The Neat Programming Language by WhereIsTheTruth on Monday December 25, 2023 @06:02PM (#38767151)
Did you attempt to submit PRs to D for the features you have listed?

It would be indeed quite neat (pun intended) to see D adopt them as well, specially sumtypes, Rust went ahead and made enums better, it's quite an expected feature for a language at this point

Re:The Neat Programming Language by FeepingCreature on Monday December 25, 2023 @06:11PM (#38767228)
We're in a DIP freeze right now. But Walter doesn't like macros and implicit conversion. Half the point of Neat is showing D devs there's no reason to be afraid of those powerful features.
Re:The Neat Programming Language by mhh__ on Monday December 25, 2023 @09:02PM (#38768303)
> DIP freeze right now

So much good has come of it...

Re:The Neat Programming Language by brabel on Tuesday December 26, 2023 @06:24AM (#38770810)
I'm getting quite interested in D... can you explain what's exactly going on with DIP1000 and whatever else you may be referring to?

Are the changes to the language going to make it much better? Break existing code? How long until they finish that, is it nearing completion or just beginning now?? So many questions as someone new to D.

Re:The Neat Programming Language by FeepingCreature on Tuesday December 26, 2023 @07:39AM (#38771278)
I have no idea honestly, it's all sort of in a state of confusion rn. The big thing coming up is editions, but that's not even slightly codified or implemented yet. I'm curious where it's going as well, I'm very hype for that approach. It could end up really good for the language. Or it could all sort of come to nothing. We'll see over the next years.
Re:The Neat Programming Language by brabel on Tuesday December 26, 2023 @06:20AM (#38770785)
Just to clarify for anyone who may misunderstand this: D has sum types: https://dlang.org/phobos/std_sumtype.html

The problem the OP was talking about is that in D, you cannot implicitly use an `int`, say, where `SumType!(int, string)` is expected.

You need something like this:

    alias StrOrInt = SumType!(int, string)

    void takeStrOrInt(StrOrInt s)
    {
      writeln(s);
    }

    StrOrInt value;
    value = 10; // ok
    value = "foo"; // ok

    takeStrOrInt(value); // ok
    //takeStrOrInt(10); // not ok
    //takeStrOrInt("foo"); // not ok

    takeStrOrInt(StrOrInt(10)); // ok
    takeStrOrInt(StrOrInt("foo")); // ok
Even though this is not perfect, it works quite well (I believe it's zero cost to do `StrOrInt(10)` for example, but I'm a D newbie). It's a bit crazy for me to see people creating new languages instead of help improving existing ones because of minor stuff like this. The effort to create a language and a stdlib and a package manager etc. is ridiculously high compared to improving existing languages.
Re:The Neat Programming Language by FeepingCreature on Tuesday December 26, 2023 @07:36AM (#38771258)
I think you're underestimating the effort cost of D sumtypes at scale. Every individual instance of StrOrInt(10) is cheap, but once you're actually constructing structs in the same line, you end up writing a lot of terrible code like

    publish(TrackingEvent(UpdateTrackerEvent(trackerId, position)));
that just adds visual noise. And the fact that you cannot return out of sumtype apply expressions just makes so many neat idioms impossible. Something like

    Object obj = nullableObj.case(null: return false);
is just fundamentally impossible in D.

So it's not one thing, it's a lot of things coming together. :) Mostly I just realized one day that D was never going to be the perfect language for me, because it wasn't even interested in being that language.

> The effort to create a language and a stdlib and a package manager etc. is ridiculously high compared to improving existing languages.

Have you seen the DMD source code? Genuinely, writing my own compiler was easier than improving DMD.

Re:The Neat Programming Language by jqpabc123 on Monday December 25, 2023 @12:49PM (#38764515)
Looks fun ... and neat.

But the mere fact that the primary ascribed goal is "fun" suggests it is not be taken seriously for actual work projects.

Re:The Neat Programming Language by FeepingCreature on Monday December 25, 2023 @12:52PM (#38764544)
Oh no good god, Neat is definitely beta. This language has one user at the moment. Do not use it for actual work projects.

(Though I will be proper chuffed if you do. I just can not recommend it.)

To be honest, my goal is to have maybe 10 to 50 users right now. That'd be quite enough for this christmas.

Re:The Neat Programming Language by dr_kiszonka on Monday December 25, 2023 @04:11PM (#38766156)
RoR was optimized for developer happiness. Maybe a language optimized for fun could be used for serious work too?

https://rubyonrails.org/doctrine

Re:The Neat Programming Language by 7thaccount on Monday December 25, 2023 @05:19PM (#38766723)
There's a few languages that claim to be optimized for fun (among other things). One example is Raku. I think -o Fun, is written somewhere.
Re:The Neat Programming Language by logicprog on Monday December 25, 2023 @05:45PM (#38766998)
Hey, I've been trying to not interact on social media much anymore but I just wanted to let you know that this looks like a pretty great (neat :)) little language! I'm very comfortable using Rust so I'm probably not going to end up using it, but my girlfriend is a data scientist who only knows Python and recently tried to start programming a game involving nbody simulation in Python, only to find that for the type of games she was trying to make Python was far too slow, and she's been really struggling to find a language that's relatively close to systems programming level (since she doesn't want to use an established engine) that also uses concepts and paradigms she understands and has reasonable syntax and stuff, and this looks like exactly what she's been looking for! When I sent her the link she got extremely excited, even more so when she saw that you had examples that were making games and using sdl. I hope you keep working on this language because I think it really does hit a nice (if niche) sweet spot!

As a funny side note, I read the part on your website where you talk about why you chose reference counting over garbage collection, and despite your light-hearted resentment of the fact that garbage collection is such a turn off for people, the fact that your language doesn't use garbage collection is one of the major factors in why she might end up using it lol. We decided not to do C# (my first suggestion actually) because since she doesn't want to use an engine, it wouldn't be used just as a scripting language, but for the entire object model and update loop and so on, so GC would be a dealbreaker. Sorry-

(tiny rant mode as a hobbyist gamedev myself) there is actually a good reason for this -- it is much easier to do multithreading when you don't have a separate thread going over all shared memory, and it's much easier to do a soft real time thing like game development if your memory allocation and deallocation stays relatively consistent and predictable, even if it is slower overall. Also, yes malloc may cause variable slowdowns too, but definitely to a smaller degree/varience than the average garbage collector and more predictably since you can control when allocations happen; otherwise there wouldn't be a noticeable difference between using garbage collected and non garbage collected languages for writing large-scale games. Plus, in any case, that's the reason why game developers tend to try to limit dynamic allocation at runtime in the first place.

Re:The Neat Programming Language by FeepingCreature on Monday December 25, 2023 @05:58PM (#38767113)
Did she find the built-in vector types yet? :) Small-scale gamedev is one place where I think this language could shine. Anyway, please also tell her to hit up the Discord (or IRC) for any questions!
Re:The Neat Programming Language by logicprog on Monday December 25, 2023 @06:58PM (#38767528)
> Did she find the built-in vector types yet? :)

Not yet, but I'm sure she'll be overjoyed to! She's so excited about this language, it'll finally make low level small scale gamedev accessible to her! :D

> Anyway, please also tell her to hit up the Discord (or IRC) for any questions!

I will! I'm sure she'll be excited there's an IRC

Re:The Neat Programming Language by frizlab on Monday December 25, 2023 @07:09PM (#38767617)
I’m very curious, did you consider Swift? It’s ARC, has C interop and is easy to read/write.
Re:The Neat Programming Language by logicprog on Monday December 25, 2023 @10:33PM (#38768705)
I'll be real honest I'm personally just not a fan of it (or Apple's development tools in general) so it didn't really cross my mind. But if Neat doesn't work out I'll keep this suggestion in my back pocket just in case bc tbh it does make a lot of sense!
Re:The Neat Programming Language by vfclists on Tuesday December 26, 2023 @08:45AM (#38771690)
Ask your girlfriend to checkout Nim
Re:The Neat Programming Language by logicprog on Tuesday December 26, 2023 @01:10PM (#38774214)
Actually after we dismissed C# it was the very next one I suggested! In theory it would've been a quite good fit, so it's a solid suggestion. It just didn't really click for her for some reason, possibly partly because when I was looking through its forums for some information on it I came across some really annoying rants from the language's BDFL, and when I showed them to her it really made her feel like it would be difficult and annoying to interact with the community. But that's just a guess idk
Re:The Neat Programming Language by vfclists on Tuesday December 26, 2023 @05:24PM (#38776755)
I think the BDFL is okay.

He doesn't have much time for the agents of corporations who through their foundations and charities aim to influence and seize control of such groups with their demands for CoCs, DEI in return for some funding and their choice of board appointees.

Nim has been getting along fine without them and will continue to.

Re:The Neat Programming Language by mhh__ on Monday December 25, 2023 @08:55PM (#38768263)
A pleasant surprise seeing it on the frontpage.
Re:The Neat Programming Language by FeepingCreature on Monday December 25, 2023 @09:10PM (#38768330)
Yeah I think I'dve been crushed if this had ended up at like three upvotes, lol.
Re:The Neat Programming Language by AndruLuvisi on Monday December 25, 2023 @09:42PM (#38768491)
Thank you for sharing!

I didn't notice any mention of tail calls. Does it support proper tail calls?

Re:The Neat Programming Language by FeepingCreature on Tuesday December 26, 2023 @05:04AM (#38770363)
Not as an enforced thing. To be honest, I'm personally not too into recursion as a "must have" feature.