this post was submitted on 28 Mar 2024
246 points (94.2% liked)

Rust

5807 readers
84 users here now

Welcome to the Rust community! This is a place to discuss about the Rust programming language.

Wormhole

!performance@programming.dev

Credits

  • The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)

founded 1 year ago
MODERATORS
 

Slide with text: “Rust teams at Google are as productive as ones using Go, and more than twice as productive as teams using C++.”

In small print it says the data is collected over 2022 and 2023.

you are viewing a single comment's thread
view the rest of the comments
[–] asdfasdfasdf@lemmy.world 2 points 6 months ago (3 children)

Why would it just be best effort? To find references for a specific thing, it still would parse an AST, find the current scope, see it's imported from some module, find other imports of the module, etc.

[–] Buttons@programming.dev 5 points 6 months ago* (last edited 6 months ago) (2 children)
if random() > 0.5:
    x = 2
else:
    x = "hello"

Where is the definition of x? What is the type of x? If you can't identify it, neither can the LSP.

This kind of thing actually happens when implementing interfaces, inheritance, etc. Thus, LSPs in dynamic languages are best effort both theoretically and in practice.

[–] Miaou@jlai.lu 1 points 6 months ago (1 children)

Tbf this example can be deducted as string | int just fine.

[–] SorteKanin@feddit.dk 1 points 6 months ago

The real problem is when you start using runtime reflection, like getattr(obj, "x")

[–] asdfasdfasdf@lemmy.world 1 points 6 months ago* (last edited 6 months ago) (1 children)
  1. Look at entire file instead of snippet.
  2. If there is anything that could create a variable x before this area, then that's where x originates. If not, and if it's a language where you can create x without using a keyword like let or var, then x is created in the scope in your snippet.

Types are not necessary at all.

[–] Buttons@programming.dev 2 points 6 months ago (1 children)

then x is created in the scope in your snippet

Saying "x is defined somewhere in the entire program" isn't satisfactory to many users. Also, you didn't tell me what type x has. Can I do x + 5?

[–] asdfasdfasdf@lemmy.world 1 points 6 months ago (1 children)
  1. That isn't what I said at all. Reread?
  2. Find references / go to definition / rename has absolutely nothing to do with types.
[–] FizzyOrange@programming.dev 1 points 6 months ago (2 children)

Find references / go to definition / rename has absolutely nothing to do with types.

It absolutely does. Without static types an IDE/LSP can't reliably find all the references / definition and therefore can't refactor reliably either.

Consider something like this:

class Foo:
  bar: int

class Baz:
  bar: str

def a(f: Foo) -> int:
  return f.bar + 1

def b(f: Baz) -> str:
  return f.bar + "1"

Now imagine you want to rename Foo.bar or find all references to it. Impossible without the type annotations.

[–] asdfasdfasdf@lemmy.world 1 points 6 months ago

Ah, I see. You're talking about object properties. I don't see any issue with finding references to variables, but for properties, yeah.

[–] SorteKanin@feddit.dk 1 points 6 months ago

It breaks down when you do runtime reflection, like getattr(obj, "x").

[–] FizzyOrange@programming.dev 1 points 6 months ago (1 children)
def get_price(x):
   return x.prize

Ok imagine you are a LSP. What type is x? Is prize a typo? What auto-complete options would you return for x.?

[–] asdfasdfasdf@lemmy.world -1 points 6 months ago (1 children)

I didn't say types. I said find references / go to definition / rename.

[–] FizzyOrange@programming.dev 2 points 6 months ago

How are you going to find references to prize, go to its definition or rename it without knowing what type x is? It's impossible without static types.