r/Compilers • • 15d ago

optimistic or pessimistic compiler?

for those that compose and craft compilers, do you find the results better and more satisfying for you if the compiler you work on is permissive/optimistic or strict/pessimistic?

permissive/optimistic here means that the starting point is the compiler assumes the line of code that it is parsing/evaluating is probably ok but needs to pass some checks before translating to the target backend? (this is “the compiler is your friend” approach)

strict/pessimistic here means that the starting point is the compiler assumes the line of code that it is parsing/evaluating has something wrong and its job is to discover that wrong thing, and it is disappointed when the line passes all checks before translating to the target backend? (this is “the compiler is the teacher we’ve all had at one point in our life where they assume you’re going to do something bad as soon as they’re not looking” - and they’re not wrong)

obviously there has to be some balance here, but i’m curious, what has been your experience with these two approaches?

9 Upvotes

16 comments sorted by

View all comments

Show parent comment

2

u/matthieum 15d ago

I consider myself intelligent. Anecdotes (IQ, relatives, friends, colleagues) all point to me being intelligent.

Doesn't mean I can't trip on my own feet, accidentally omit a word when typing a phrase, or a ! sign when typing a boolean condition.

I am intelligent, but I am all too fallible, especially when my damn brain is already thinking about the next thing when I'm still typing the previous one.

2

u/nzconstructionlawyer 15d ago

Good luck ever coming up with a clever enough compiler that it can identify you left out a ! in a condition lol

1

u/matthieum 14d ago

Indeed :'(

Fortunately there are some more obvious errors for the compiler to pick, like type errors -- returning a scalar instead of a list containing that scalar -- etc...

And linters can call out on dubious code. For example, in Rust's built-in linter (Clippy) there's a lint to warn about implementing operator X using operator Y. It's not always dead-on -- implementing exponent arithmetic, for example, trips it -- but... it's caught quite a few cases of copy/pasta/oops.

0

u/FluxProgrammingLang 15d ago edited 15d ago

Those are obviously grammar and syntax errors, which are caught. Why do people insist on the “most vexing parse” when reading what someone said? It’s like me telling you the oven only goes to 450°F, and you say well mine does, my family’s oven does, my neighbors oven does, but we don’t use plastic cooking pans cause they’ll melt. No way, really? Effectively reducing what i said to its most incorrect interpretation.

Here’s an example, say I assign a u64 ptr address to a u32 ptr without casting the value. This is an error in a lot of languages. Not in mine because I have a reason to do that sometimes.

Note to OP: be prepared for people to do what matthieum does to things you say.