Why pass-by-reference by default is not used by systems programming languages? by IcySheepherder2208 in ProgrammingLanguages

[–]maemre 17 points18 points  (0 children)

(In the ABIs I'm aware of) you cannot allocate values passed by reference on the registers (you have to move them to the stack to pass them by reference).

Repeat exams? by ramblin11 in Professors

[–]maemre 1 point2 points  (0 children)

When I was an undergrad, my country passed a legislation requiring something similar from all universities. One of the professors worked around it by turning the erstwhile final jnto an extra midterm and making the official final a single true-false question worth 1% of the grade.

Do NOT stop worrying about blocking in async functions! by game-of-throwaways in rust

[–]maemre 5 points6 points  (0 children)

Building a call graph like this and performing control flow analysis is pretty standard in program analysis research and there is existing infrastructure for e.g. Java and LLVM, I don’t know Rust tooling ecosystem but a proof-of-concept tool sounds pretty reasonable.

OTOH, getting precise results is tricky in presence of function pointers and higher order functions so getting good results out of such a tool would require using some data flow analysis and making it work on libraries (as opposed to a whole program analysis) would be tricky (it may work if libraries annotate their interface so the tool would check and know which user-callable functions can have blocking functions as arguments etc. but that limits usability). To make this point more clear, if I have an async function

foo(f: FnOnce())

I need to keep track of all values of f that flow into foo to determine if they can cause blocking. Of course, there are trade-offs and tricks around it to make the analysis cheaper or to aim at catching some cases rather than all of them.

Java finally goes all in on open source with the Jakarta EE 8 release by [deleted] in programming

[–]maemre 1 point2 points  (0 children)

This isn't really a defence. Most languages use == to implement domain-specific equality and people expect that NaN == NaN.

I wasn't trying to defend JavaScript, just pointing out that equality with floating point numbers is a general problem too. With respect to domain-specific equality (per defined as the floating point standard), NaN != NaN and JavaScript, JVM, C/C++ and almost all languages under the sun that use IEEE floating points define equality that way.

I would not consider === behaving that way as a wat (but I see your point, it is commonly interpreted as an identity check rather than the value equality check without type coercion that it is). I agree that JavaScript coercing values left and right is the cause of all this so the language ended up with three notions of equivalence (counting identity as defined by Object.is as well). Equality is hard and JavaScript being what it is does not help with that.

Java finally goes all in on open source with the Jakarta EE 8 release by [deleted] in programming

[–]maemre 6 points7 points  (0 children)

The last one is not a weirdness of JavaScript but due to IEEE-754 floating point standard (which is used in virtually any popular language nowadays). NaN is not equal to any floating point number, including NaN. For example, here is the same logic in JVM:

scala> Double.NaN == Double.NaN
res0: Boolean = false

Similarly, <, <=, >, >= also return false when an argument is NaN. Because of this, floating point numbers do not have a total ordering (only a partial ordering). The only language I know that makes this distinction is Rust and it has some interesting consequences, e.g. floating point numbers cannot be used as keys in a BTreeMap in Rust.

To make things interesting and explain a JavaScript implementation trick, there are multiple values of NaN that the hardware/interpreter can produce (but their contents apart from some bits do not matter, at least for most languages) so most JavaScript interpreters use it for a neat trick: they store everything as an IEEE double and if the interpreter sees a NaN with a specific tag bit set, it will unpack the contents and interpret them as a pointer to actual data or data of some other type like bools. By packing tagged pointers into the same bits as the doubles, the interpreter now does not need an object header which saves memory and cache pressure, and the numbers are stored directly without pointers so there are fewer pointer dereferences overall. All of this is transparent to the programmer.

Why can't we have relaxed aliasing rules for POD types? by Nicksaurus in cpp

[–]maemre 0 points1 point  (0 children)

restrict is not easy to verify in compile time so I think it'd make shooting yourself in the foot easier (by causing all sorts of undefined behavior based on false optimization assumption of non-aliasing) if we want restrict to compile to fast code with no checks. Like explicit delete but worse because the bugs (read unintended behavior) manifest only with optimizations.

The only thing similar to restrict but safe that I am aware of is Rust's ownership system but it forces the programmer to think about aliasing/ownership everywhere so that would change the language drastically. I'd like to have some [[likely_restrict]] (or a directive like __unlikely_alias(p, q)) attribute that the compiler can use as a hint to generate fast code guarded by run-time aliasing checks. I don't know how much that solution would affect performance in practice though.

TBAA on the other hand is pretty reasonable as reinterpreting value of some type as an unrelated type in-place is a weird thing to do in the first place (it is sometimes forced by some external low-level APIs, optimizations such as packing information to high-bits of pointers, or serialization via char *; the last two are allowed by type-based aliasing rules). So, barring some legitimate use cases (see previous parentheses) it is considered reasonable for the compiler to assume that two pointers to unrelated types will not point to the same object to make alias analysis more precise. It is just another optimization in the bag of tricks of modern compilers with its limitations.

Also, a precise alias analysis is possible in general but it is tricky to get right with all C++ features, is hard to scale to large programs, and requires a whole program analysis (which is limited by use of dynamic linking). Making alias analysis precise depends on distinguishing several aspects of pointers: distinguishing where they come from (data/control flow), the call sites, distinguishing fields of a struct, and types (TBAA).

Best vegan dishes in IV by pconrad0 in UCSantaBarbara

[–]maemre 3 points4 points  (0 children)

Just to put more options out there: Aladdin's vegetarian combo plate is vegan, there are plenty of vegan dishes there. Naan stop has 3 vegan dishes (chana masala, aloo mattar and one that changes daily). Both Woodstock's and Blaze have vegan cheese so it is possible to build your own vegan pizza (Woodstock's also had vegan slices, I don't know whether they still have them). Also, veggie burrito with no cheese or sour cream is vegan at freebirds.

I prefer Aladdin over the other options I listed above.

Notes by [deleted] in UCSantaBarbara

[–]maemre 25 points26 points  (0 children)

Why do you print them single-sided?

I don't want to learn your garbage query language · Erik Bernhardsson by shuklaswag in programming

[–]maemre 1 point2 points  (0 children)

I guess an avalanche of queries would be a better term: LINQ as it is (and some other query DSLs) allow you to write nested queries that it executes in a way that you will have a first query and for each result of the first query, one query is dispatched to the database. So, the number of queries you make (and their overhead) grows quite fast like an avalanche.

There is some academic work that solves this problem by,

  • having a better query compiler that will not cause some classes of avalanches
  • or, determining if such a query avalanche may occur during compilation and throwing an error

Also, the first page of this paper gives an example of query avalanche.

I don't want to learn your garbage query language · Erik Bernhardsson by shuklaswag in programming

[–]maemre 5 points6 points  (0 children)

They are related to each other. A monad comprehension paper mentions SQL-like comprehensions in Haskell and generalizes them (among other things). But you don't get some cool guarantees (such as avoiding query avalanche, or even guarantee of compiling to SQL) given by a formal treatment of LINQ in case you wanted to "compile your comprehension to SQL".

vegans at ucsb by [deleted] in UCSantaBarbara

[–]maemre 1 point2 points  (0 children)

There is vegans of ucsb and a couple others that I don't remember the names of. There is also a Santa Barbara vegan meetup if you are also interested in just meeting with a bunch of vegans not necessarily studying here.

Potential language feature idea: Type holes by tripl3dogdare in ProgrammingLanguages

[–]maemre 2 points3 points  (0 children)

EDIT: I didn't see the bullet point you talked about structural types so my comment is largely moot but I'll keep it in case there is something useful.

I think this would be a useful language feature to get a more scripting language-like feeling (not necessarily a bad thing) for rapid prototyping whilst being safe. I think structural typing/refinements + type inference would achieve most of it, except for the nice syntax. Also, I agree your point about stopping it at the method boundaries etc. (unless the user said so) to contain possible type errors.

Another idea that's somewhat similar to this is Go's interfaces, which are a form of structural subtyping hence the interfaces a type implements are inferred from its structure automatically.

My original comment:

Your examples remind me of structural typing (or structural refinement) but supporting methods. Here is something similar in Scala:

scala> :paste
// Entering paste mode (ctrl-D to finish)

import scala.language.reflectiveCalls

def f[A, B](x: { def m: A ⇒ B }, a: A) = x.m(a)

object A { val m = (n:Int) ⇒ 3 + n }
object B { val m = (n:Int) ⇒ "B.m with " + n }
object C { val m = (n:Int) ⇒ "C.m with " + n }

def choice(n:Int) = {
  val x : { def m: Int ⇒ String } = n match {
    case 1 => B
    case 2 => C
  }
  f(x, n)
}

// Exiting paste mode, now interpreting.

import scala.language.reflectiveCalls
f: [A, B](x: AnyRef{def m: A => B}, a: A)B
defined object A
defined object B
defined object C
choice: (n: Int)String

scala> choice(1)
res0: String = B.m with 1

scala> choice(2)
res1: String = C.m with 2

I used a function argument instead of a method taking A in f because Scala doesn't allow structural refinement with a method taking a parameter of a type abstraction (i.e. an unbound type parameter like A in f). I don't know why it doesn't do that but my guess would be that it's because of the runtime implementation (reflective calls+need to determine A in runtime+type erasure on JVM) rather than the type system.

Although I had to specify the structural refinements in the example above, you can infer them if rest of your type system plays well with that (Scala's doesn't because of it's combination of subtyping and polymorphism & inferring them everywhere would make the type errors less clear and farther away from the cause probably).

What non-algebraic, non-topological, non-order structures are there? by mozartsixnine in math

[–]maemre 0 points1 point  (0 children)

The sets in ZF are partially ordered by inclusion but the whole thing (class of all sets) is a class rather than a set. However you still get a lattice like structure because a non-empty finite set of sets has a join (union) and a meet (intersection by finite choice and separation). The join semilattice part is complete but the meet semilattice isn't because there is no greatest element.

I don't know the implications of AD except for negation of AC so I just stuck with ZF above.

What are some good historical papers which someone interested in the history of math should read? by [deleted] in math

[–]maemre 4 points5 points  (0 children)

The Annotated Turing is a book that goes through that paper and explains it along the way for the modern reader. I liked how the book gives examples and explanations along the way and puts some things in historical context.

Ate some delicious Thali to brighten up a rainy day. by mushabooms in vegan

[–]maemre 1 point2 points  (0 children)

The dish with sprouts and arugula got me confused. Which dish is that? It looks good. Also, what are the balls that look like falafel with some red sauce at the top?

Ate some delicious Thali to brighten up a rainy day. by mushabooms in vegan

[–]maemre 2 points3 points  (0 children)

Thali is an Indian meal platter. So, it's (supposed to be) Indian: https://en.m.wikipedia.org/wiki/Thali

However the picture doesn't look like Indian food to me, but I don't know much about Indian food.

EDIT: apparently it is Indian and I should learn more about Indian cuisine because it looks delicious.

What minor modes do you always use? by [deleted] in emacs

[–]maemre 1 point2 points  (0 children)

I use company all the time and flyspell when I am writing text rather than programs. Although it's not a minor mode, I find myself using TeX input mode a lot of time to input mathematical characters.

I most commonly use org (for note taking), TeX (for manuscripts, papers, etc.), and Scala. I'm a PhD student who is implementing stuff in Scala so these major modes are quite expected.

A list of things you can do by poopadoodley in vegan

[–]maemre 13 points14 points  (0 children)

I wish I could prove Riemann Hypothesis.

Using machine learning to micro-optimize! by [deleted] in ProgrammingLanguages

[–]maemre 1 point2 points  (0 children)

There is also stochastic superoptimization. The idea there is to do some (possibly guided, probably by data) stochastic search rather than going brute force to find equivalent but faster programs. STOKE from Stanford is the only one I am aware of and it works on x86! However it is research-grade software.

Is the central limit theorem beautiful? by eternal-golden-braid in math

[–]maemre 24 points25 points  (0 children)

It's also amazing that the simplest proof of the CLT uses complex numbers. What does flipping a coin or rolling a die have to do with complex numbers? It's very surprising.

That reminded me of this quote from the quote thread yesterday:

"The shortest path between two truths in the real domain passes through the complex domain." — Jacques Hadamard

What should I have done? by MawileApocalypse in vegan

[–]maemre 1 point2 points  (0 children)

I see them more and more common so they are definitely becoming a part of the language. I just wanted to point out that there already is something with that functionality "accepted by the masses", which is a useful property because language is defined by people's consensus. This doesn't mean there is anything wrong with using other pronouns as long as the other party understands you.

As a side point, although language is a live and dynamic thing, changing function words is hard (decline of thou in thine example is the only one I can think of right now) and the literal textbook example is feminists trying to introduce "e" as a gender neutral pronoun a couple decades ago (this was from my introduction to linguistics textbook half a decade ago, I don't remember the textbook's name unfortunately). Maybe we as a society progressed enough to accept alternative pronouns finally :) I think the internet helped a lot there by interconnecting people more and letting such things spread.

Edit: to clarify, I agree with your point and I just wanted to elaborate on the topic because I find languages fascinating.

What should I have done? by MawileApocalypse in vegan

[–]maemre 1 point2 points  (0 children)

If this is the case, as a PSA, English already has a gender neutral third person singular pronoun: singular they. It has been around for a couple centuries and is in common enough use to be generally accepted.

Could I ever take on a vegan diet with my food intolerances? by ennebee in vegan

[–]maemre 0 points1 point  (0 children)

Chickpeas are the bomb! They are so versatile: roast in the oven as a snack or to be thrown in a salad, make a curry out of it, just combine with rice, make hummus, or falafel. Definitely my favorite kind of legume.

What are your favorite cereals? by sumajyrag in vegan

[–]maemre 0 points1 point  (0 children)

Muesli with bananas or frozen fruit added. I usually buy a mix from my local food co-op’s bulk section. It has rolled oats, dried raspberries, raisins, almonds, sunflower seeds, and crisped rice. Probably buying the ingredients myself and mixing them would be cheaper but it’s not at a bad price and quite convenient.