Sorry if I’m missing some sarcasm here, but if this is all you have to contribute, then as a professional software developer, I’d much rather work with the author of the article on a daily basis.
Sorry if I’m missing some sarcasm here, but if this is all you have to contribute, then as a professional software developer, I’d much rather work with the author of the article on a daily basis.
Pushing HTML even further, one could say it’s a declarative programming language that programs a UI in a mostly-stateless manner (inputs aren’t really stateless but you can argue the state is provided by the UI rather than managed by HTML).
I’m not sure I’d make this leap myself though, I have a hard time classifying it (or any other markup language) as a PL. As far as I am aware, you can’t really program a state machine with pure HTML, though you can accept inputs and return outputs at least.
Two thoughts come to mind for me:
Would it work to write the query as a common table expression, then select your columns from that table and join it with a count(*)
aggregation of the table?
Or look at Python and their urllib, urllib2, new urllib, and the requests package on PyPi.
We already sort of saw this in Rust with crossbeam and standard channels, until of course they replaced the standard lib implementation with crossbeam’s implementation.
I think it’s good to document why things are done, but extracting things out into another function is just documenting what is being done with extra steps. This also comes with a number of problems:
//
or #
would have made the code just as readable.If those functions are huge units of work or pretty complex, I can agree. For most cases though, a simple code comment should do to explain what’s going on?
While impressive, a minifier can bring it down to 1 line of JS! I do like that this can function as a reference for making simple canvas-based games though.
Still working on an assertions library that I started a few weeks ago. I finally managed to get async assertions working:
expect!(foo(), when_ready, all, not, to_equal(0)).await;
It also captures values passed down the assertion chain and reports them on failure (without requiring all types to implement Debug
since it uses autoref specialization).
Hopefully it’ll be ready for a release soon.
I also avoid query syntax generally because I find it hard to map to method syntax with more complex queries. It’s a cool concept though, despite it being painful to use.
For library code - yes, you’d usually want to direct users to the correct way of using the library, so you’d be more likely to come across fallible build
functions or a bunch of type parameters to constrain when it can be called.
For applications - honestly, it’s your code, so do what makes sense to you. Using a build function can help you ensure your settings were fully configured before using them, but it’s up to you if that’s the direction that makes the most sense to you. One benefit is you only need to perform the check once, but the downside is having another “built” type that you need to keep in sync with the original type. You can also look at libraries like derive_builder
if you want to have your builder generated for you to avoid needing to manually update two separate types.
C# also has a built-in query language (LINQ). I think it might just be simpler to group them together to avoid nuances like these, though I don’t think anyone would complain about not seeing LINQ on a query language list either.
I wonder how many people learned Lua for this reason (CC and friends).
To be clear - I’m referring to devices with, say, 128MiB of device storage and memory when I refer to low memory machines (which I’ve developed for before actually). If you’ve got storage in the GB, then there’s no way optimizing for size matters lol.
My understanding is that should almost only ever be set for WASM. Certain low-memory machines may also want it, but that’s extremely rare.
I’m not sure who’s recommending it, only ever seen it recommended for WASM applications.
Anytime anyone mentions integrating an HTTP client into Rust’s std, all it takes is one good Python anecdote to shut that discussion right down.
Having the standard library be stable and not try to add a bunch of support for changing standards is a long-term benefit to the language. Having “de-facto standard libs” with crates like url
, http
, etc ends up being better because they can evolve independently from the standard library, at the pace their respective domains evolve.
Although, I suppose an argument could be made that url
is unlikely to really evolve anymore.
Ignoring the rest, just some thoughts about the list of proposed features:
A
capture
trait for automatic cheap clones
Automatic implicit cloning would be useful for high level developers, but not ideal at all for low level or performance-sensitive code. It’s not the case that anyone using a shared pointer wants to clone it all the time. The high level usecase doesn’t justify the cost assumed by the low level users.
Instead, being able to wrap those types with some kind of custom “clone automatically” type feels like a middle ground. It could be a trait like mentioned, or a special type in the standard library. Suppose we call it Autoclone[T]
or something (using brackets because Lemmy nonsense). Autoclone[Rc[T]]
could function like the article mentioned.
Automatic partial borrows for private methods
Having “private” and non-“private” methods function differently feels like confusing behavior that should be avoided if possible. Also, “private” I assume refers to pub(self)
methods (the default if unspecified), which is “module-level” methods (so accessible within the module it’s defined in). Anyway, there are years of discussion around this so I’ll just defer to that as to why it’s not in yet.
I agree with the urge to make it happen though. Some method of doing partial borrows for methods would be nice.
Named and optional function parameters
This is what prompted me to even comment. What “every language” does for complex constructors is different per language. C#, for example, supports both named and optional parameters, but construction usually uses an object initializer:
var jake = new Person("Jake")
{
Age = 30,
// ...
};
This is similar to Rust’s initializers:
let jake = Person {
age: 30,
...Person::new("Jake")
};
Where it gets tricky is around required parameters. Optional ones don’t really matter since you can use the syntax above if you want, or chain methods like with the builder style.
As for the overhead of writing builders, there’s already libraries that let you slap #[derive(Builder)]
on types and get a builder type automatically.
As for optional parameters, how those are implemented differs between languages. In C#, default values must be constant values. In Python, default values are basically “global” values and this nonsense is possible:
def count_calls(count=[]):
# if unset, count is a global list
count.push(0)
return len(count)
Anyway, all this is to say that the value of optional parameters isn’t obvious.
Named parameters is more of a personal choice thing, but falls apart when your parameter has no name and is actually a pattern:
async fn get_foo(_: u32) {}
Also, traits often use names prefixed with underscores in their default fn impls to indicate a parameter an implementer has access to, but the trait doesn’t use by default. Do you use that name, or the name the implementer defined? I assume the former since you don’t always know the concrete type.
Faster unwrap syntax
We have that, it’s called the try
operator.
Okay I know it’s different, and I know everyone’s use case is different, but I’ve been coding long enough to know that enabling easy unwraps means people will use it everywhere despite proper error handling being pretty dang important in a production environment.
Thinking of my coworkers alone, if we were to start writing Rust, they’d use that operator everywhere because that’s what they’re familiar with coming from other languages. Then comes the inevitable “how do I add a try-catch block?” caused by later needing to handle an error.
Anyway, I prefer the extra syntax since it guides devs away from using that method over propagating the error upwards. For the most part, you can just use anyhow::Result
and get most error types converted automatically.
Try trait
Yes please.
Specialization
Yes please.
Stabilizing async read/write traits to standardize on an executor API
I’d want input from runtime devs on this, but if possible, yes please.
Allowing compilation of builds that fail typechecking
???
How is the compiler going to know how to compile the code if it doesn’t know the types? This isn’t Python. The compiler needs to know things like how much memory to allocate, and there’s a ton of potential unsound behavior that can occur from treating one type as another, even if they’re the same size.
Anyway I’ll save the rest for later since I’m out of time.
Speaking as someone with a MTF close friend and NB spouse, but the term used in the article is the term everyone around me used when I was growing up. That term may be obsolete now, and if so, the author simply needs to be informed. There’s no need to assume they meant harm by it.
If they knowingly used a term that may offend, then that’s of course a separate issue.
I was mostly looking for something more composable, similar to how jest
works. Some ideas that I’ve been working on are assertions like:
expect!([1, 2, 3])
.all()
.to_be_less_than(5);
I also have some ideas around futures that I’d like to play with.
Adding a single unused function should no effect on runtime performance. The compiler removes dead code during compilation, and there’s no concept at runtime anyway of “creating a function” since it’s just a compile-time construct to group reusable code (generally speaking - yes the pedants will be right when they say functions appear in the compiled output, to some extent).
Anyway, this can all be tested on Godbolt anyway if you want to verify yourself. Make a function with and without a nested unused function and check the output.