Better HN
topnewbestaskshowjobs
Log inSign up

GrumpySloth

4,901 karma · joined Sep 13, 2020 (6y ago) · 1,641 submissions

Submissions

comment 5y ago · link · parent

Sorry. I didn't see it before. You're right.

comment 5y ago · link · parent

[EDIT: comment applicable only to an older version of the parent comment]

This "foo" still suffers from the same problem as "Option::map" does: it is hard-coded for functions of fixed arity (2 in this case, 1 in Option::map's case).

Needing to write this function doesn't shorten the code. The SML-inspired solution allows one to write an "Option::map" which accepts functions of all possible arities (since they are all 1).

But yes, if there are a lot of places where I want to call "Option::map" for an "f" which takes 2 arguments, that could work. Although, personally, I think I'd still opt for an explicit lambda, in order to communicate intent more directly (avoid one level of indirection).

comment 5y ago · link · parent

> Having enum variants be structs has been proposed

That's great news.

> that could solve your issue if `mem::disciminant<Enum::Variant>` returned what you wanted.

I think you misunderstood, or I explained it poorly.

Given an:

  enum Enum {
      A(int),
      B,
  }
I would like mem::Discriminant<Enum> be the same type as if there was such a definition in code (illegal in Rust, because Rust doesn't have specializations):

  enum mem::Discriminant<Enum> {
      A,
      B,
  }

comment 5y ago · link · parent

One thing that I repeatedly bump into in Rust is the oddity of multi-argument functions. To explain the problem, let's look at another language for a moment: in SML there is no such thing as multi-argument functions per se. There are two ways to write them anyway:

* the function's argument is a tuple (this is the more common way, not only in SML, but also how it's done most commonly in maths);

* currying.

I'm not a fan of currying, because it singles out the first argument over the others. However, the first approach (tuples) is very ergonomic, because now you can pass the return value of one function as an argument to a "multi-argument" function. One application of that is function composition. But another is a simple map. I've lost count of how many times in Rust I had an "o: Option<(A, B)>" and a "f: fn(A, B) -> C" and couldn't call "o.map(f)"; instead the programmer is forced to write more noisy code with lambdas. And lambdas sometimes don't play well with the borrow checker for mysterious reasons (even those that don't capture anything).

Also, I think it would be nice if the compiler generated named discriminants for every enum. Currently, "std::mem::discriminant" returns an opaque "std::mem::Discriminant<T>" (which doesn't have a name). In order to compare discriminants I need to create a full-blown enum value and extract the discriminant from it later. I've worked around this problem by using the "strum" crate, which has a macro to produce another (plain) enum, but having the discriminant type be named "std::mem::Discriminant<T>" (to signal the connection to the original enum) and have named variants at the same time would be the best of both worlds.

EDIT: If I knew more about possible breakage caused by my first suggestion, I could probably start working on an RFC. However, I feel I don't have enough knowledge about Rust to anticipate that.

For my second suggestion I think I'm going to try to propose that. I'm reading the docs on the process now.

comment 5y ago · link · parent

Unless it's from a Nigerian prince.

comment 5y ago · link · parent

> don't do anything that would get you on a terrorist/cybercrime/pedo list in the first place?

This is going to be difficult: <https://arstechnica.com/information-technology/2014/07/the-n...>

comment 5y ago · link · parent

Those comments aren't entirely unreasonable. Money is important, but it can't be the be-all-and-end-all of a company.

There are companies like Sun Microsystems, and then there are companies like Oracle.

There are companies like Gandi, and then there are companies like GoDaddy.

There are companies like Fastmail, and then there are companies like Google.

I prefer to look up to the first group.

comment 5y ago · link · parent

Yes. I think the author of the paragraph wrote about Buddhism in the context of Tibetans. It isn't applicable to Mongols as well.

comment 5y ago · link · parent

The practice is similar. The motivation is different. The quoted paragraph may be phrased a bit poorly. I don't think the Mongolian practice has anything to do with Buddhism.

comment 5y ago · link · parent

It isn't an inevitable product though. E.g.[1]:

> Mongolian culture is famous, along with Tibetans, for "sky burial," which leaves the body of the deceased on a high unprotected place to be exposed to the elements and devoured by wildlife. It's part of a Vajrayana Buddhist outlook about the needlessness of "respecting" the body after death.

Personally, I'd prefer if this was what would happen to my body than any Western ritual. Alas, in the West we have laws which, in practice, impose religious precepts long after the states are secular on paper.

[1]: https://www.bustle.com/articles/97030-5-interesting-death-an...

comment 5y ago · link · parent

Why is the orange colour different on macOS?

I've noticed the same effect when I switch to Mac and browse HN (the top bar becomes unreadable).

comment 5y ago · link · parent

Your comment prompted me to google for those tools once more. One that I did not know about before is Eclipse Memory Analyzer. The screenshots[1] look promising, especially "Path to GC Roots". I didn't know that was possible. Is there something comparable for .NET?

[1]: <https://www.eclipse.org/mat/about/screenshots.php>

EDIT: A bit more googling and I found <https://memprofiler.com/> for .NET which seems to have a similar feature, called "Instance Graph".

comment 5y ago · link · parent

In other news, Poland accidentally invaded Czech Republic: <https://www.independent.co.uk/news/world/europe/poland-czech...>

comment 5y ago · link · parent

Some gasses will be consumed by plants and fungi. Granted, methane won't be one of them. But CO2 will. Now, when compost is dumped on barren soil, there is nothing to consume the gasses.

comment 5y ago · link · parent

Even without LTO, linker will discard object files that aren't used (on Linux a static library is just an AR archive of object files). It's just a different level of granularity.

comment 5y ago · link · parent

> Anyone who actually prefers the UX of desktop Windows is mentally deranged

Think a bit about what you say.

comment 5y ago · link · parent

> And it's faster if and only if you're repeating division by a single number since you're still doing the equivalent of divide to get the invest

This is done at compile-time by the compiler. We're talking about division by a constant, not by a variable. So it's always faster.

comment 5y ago · link · parent

Noise dampening is still an issue. Where I'm living, the whole flat is subject to resonance, when old buses drive by. It's like living inside the throat of a bass vocalist. That, and I hear every laugh a child has outside, even though I'm on 7th floor (8th, if you count like USA-ians do). It's terrible.

comment 5y ago · link · parent

According to my naive knowledge:

1. We have more ozone holes now.

2. We weren't constantly in direct contact with sunlight. If you move past very early stages, we had shelter in forests, caves, tents, igloos.

3. When we were in direct contact with sunlight, we had a darker skin, which is more resilient to that.

Correct me if I'm wrong.

comment 5y ago · link · parent

I use Fastmail.

comment 5y ago · link · parent

@dang: This is the same mail as <https://news.ycombinator.com/item?id=26955474>, which is already on the front page. Same mail, different mailing list.

comment 5y ago · link · parent

It took this mail a bit over 3 hours to be sent to my mailbox. (I subscribe to gcc-announce.) I'm curious what the reason for such a delay is. (Nothing wrong with the delay, just curious about the technical reason.)

comment 5y ago · link · parent

Probably 0. :)

How often do you see a variable named "O"?

comment 5y ago · link · parent

While it is true that dynamic memory management in C and C++ is a source of memory corruption issues, the other great source is precisely the reluctance of many C and C++ programmers to use dynamic memory allocation instead of buffers of statically-defined sizes. E.g.

1. Functions which convert a number to a string, where the target string is a byte buffer passed into the function as a pointer argument. This allows C developers to pass pointers to statically-sized arrays of bytes, which leads to buffer overflows. (Inb4 someone shows up with "but that's the programmer's fault for not using an array that's big enough".) Example: strcpy.

2. Functions which return pointers to static storage, which makes them thread-unsafe, and even in single-threaded cases is error-prone, when you call one such function multiple times in succession (aliasing). Example: gmtime.

Both cases are very prominent in the standard library.

If instead functions allocated memory dynamically, then they would avoid buffer overflow, because size would be handled exclusively within those functions, allocating as much memory as is needed, no more, no less; instead of forcing the programmer to worry about the size at every call-site. They could also be easily made thread-safe and less error-prone (eliminating aliasing), provided that the allocator is thread-safe.

Another issue with the first case is that it leads to uninitialised variables. Often a pattern of "bool NumToString(int n, char* dst, int size);" is employed instead of "Optional<std::string> NumToString(int n);". This invites the possibility of using "dst" without checking the return value, which says if the conversion succeeded. In this case dst is most likely uninitialised, and definitely incorrect. An "Optional<std::string>" solves both issues.

comment 5y ago · link · parent

A simple "+" works as well, as long as "x" is a String, and not a &str.

Also, concatenating strings for any other purpose than printing them is a rarely done thing in my experience, no matter the language. So I don't see why we should optimize the ergonomics of something like that.

comment 5y ago · link · parent

> Some people love it, because it potentially gives you an enormous amount of leverage to solve difficult problems with careful but short solutions. I forget where I heard this joke, but you give a Java programmer some specs and he'll spend 4 hours writing code, whereas the Haskell programmer will spend 3 hours and 55 minutes meditating, then write a 10 line solution.

I prefer the "meditative" approach, because it will more often produce something readable. It looks unproductive, because there is a small number of lines produced in a given amount of time, but that's actually good. With the approach where the programmer just sits down and bangs away at the keyboard straight away, producing lines of code at uniform velocity, you end up with loads of code doing nothing, "dowork", calling "doworkimpl", stack traces 50 stack frames long where no stack frame seems to be doing any useful work. The "meditative" approach in extreme cases can produce indecipherable code with y combinators and whatnot, if your coworker is a real monk, but generally brevity seems to be a nice benchmark. All those great Haskell abstractions don't actually produce short code, it's the basic Haskell that does it. It just takes a while to arrive at such a solution, be it C or Haskell. And it's a win long-term, when you need to get back to this code to debug it. And you are going to need to get back to debug it.

See e.g. The Evolution of a Haskell Programmer[1]. It's not the great abstractions that produce the shortest code. But it is the shortest code that is the clearest.

[1]: <http://pages.cpsc.ucalgary.ca/~robin/class/449/Evolution.htm>

comment 5y ago · link · parent

In my experience, YouTube in-video links (those that e.g. show thumbnails of videos and are pointed at by vloggers with their fingers) have been broken in Firefox for years. Not that I complain, I've always been annoyed by those. I think it took me 2 years to realize that after seeing vloggers point at invisible things. I had to double-check in Chrome. (I just assumed that they forgot to add the links when editing.)

comment 5y ago · link · parent

VSCode.
1
484950
55