r/AskProgramming • u/vivaidris • Sep 21 '26
Other What is a niche feature or implementation that you love using in your go-to language?
For me, I love C++'s std::queue. Ridiculously simple, can only use the front, but so powerful.
8
Upvotes
28
u/Soft-Marionberry-853 Sep 21 '26
You know how people instinctively give preferential treatment to people that they find attractive even if it's not earned. That is how I treat languages that let functions return multiple values.
I dont know how much of my professional life has been wasted returning an array or making an object that just holds 2 integers. And it never made any sense, why does a function let you pass it as many values as you want but nope, you can only return 1 value.
5
u/qrzychu69 Sep 21 '26
Computation expressions in F#, especially the custom ones. You can have "effectful" binds to variables, and what they do depends on which builder you have.
let! a = doStuff ()will await it in task, but will do replicate the?operator from Rust inresultbuilder. And then you can gettaskResultthat will do both.Another one is also dotnet, but supports C# - expression trees.
You can do
blogs.Where(x => x.Comments.Count > 5), that's obvious for everyone. But you can also dodatabase.Blogs.Where(x => x.Comments.Count > 5).Select(x => new { Title = x.Title, Id = x.Id}). At runtime this get converted into expression tree, and the builder can translate your code to SQL, and it will only select what you actually need.What's even better, you can also build those expressions dynamically at runtime, and both the SQL part (called EF Core for those curious, best ORM out there IMO) and the expression part support anonymous records.
That means you can basically do
services.AddGraphQL<MyDatabaseModel>()and yes, it works just how you think, with paging, sorting, projecti, selecting only what you need - everything. You start with that, add some customization for auth, hide some tables, throw in some projections, add couple mutations - you get full graphql service generated for you. Sometimes that's all you need.All that works because expression trees can be created on the fly, and they can be translated to SQL, and there is reflection so you can query the structure of your classes.
It's an amazing piece of tech
8
u/generally_unsuitable Sep 21 '26
I think I wrote C for a decade before I realized that sprintf() returns the character count of the generated string. In embedded, this saves so much time it's ridiculous.
5
u/Ok_For_Free Sep 21 '26
In JavaScript, reflection is basically free.
3
u/garagedragon Sep 21 '26
So Rust has so many nice features, but here's a couple of more obscure ones.
You can pattern match multiple variants of an enum at once, so long all the names you assign have consistent types in every variant. This means if you have
Result<T, T>, you can sayOk(val) | Err(val) => ...in one line. This works even if the fields are named, so long as you discard any fields that don't show up in all branches, i.e. you can sayFoo { name,..} | Bar { name, ..} => ...if both variants have a field that's the same typeAlso, Option and Result are IntoIterable, which means among other things, if you have an iterable of them, you can flatten() it to get only the successes. It also means that you can collect() an iterable of
Result<T, E>into aResult<Vec<T>, E>which gives you either a vec of the success cases, or the first error.3
u/ern0plus4 Sep 21 '26
Rust enum - just love it.
4
u/engineerFWSWHW Sep 21 '26
I love LINQ on .NET/C#.
2
u/simonsanchezart Sep 21 '26
`next(generator, None)` in python to get the first element from a collection/generator that matches a condition
2
u/azimux Sep 21 '26
I love Ruby's blocks and (almost) everything about them. I think they were a really killer idea building on Smalltalk's blocks.
2
u/ExtraTNT Sep 21 '26
maybe
Haskell
2
u/Eleventhousand Sep 21 '26
Default properties in Visual Basic
1
u/gnunn1 Sep 21 '26
I'm not sure how niche it is, but I liked D's templatemixin feature.
https://dlang.org/spec/template-mixin.html
1
u/Daemontatox Sep 21 '26
C++ splice() with lists
1
u/Dunkelziffer17 Sep 21 '26
Xtend collection literals are really nice.
val list = #['foo', 'bar'] val set = #{'foo', 'bar'} val map = #{'foo' -> 42, 'bar' -> 23}
Other languages introduced similar constructs, of course, but I still find Xtend’s syntax incredibly concise.
1
u/marrsd Sep 21 '26
Some dynamically typed languages allow you to swap the data from under an object at runtime. For example, you could replace a module imported by another module you're testing rather than set up dependency injection to pass in mocks and stubs.
1
u/publicOwl Sep 21 '26
I miss case classes in Scala. Pattern matching, all the stuff it gives you for free…
1
u/Pzzlrr Sep 21 '26
DCGs in prolog are so nice.
1
u/Haunting_Stuff5104 Sep 22 '26
returning multiple values is the only thing keeping me sane. I will never write a struct just to hold two integers again
1
u/Astro-2004 Sep 28 '26
Go defer is a game changer in how I clean all the mess that I get when dealing with I/O or concurrent software
1
u/Darkschlong Sep 21 '26
Scanner sc = new Scanner(system.in);