• 1 Post
  • 90 Comments
Joined 9 months ago
cake
Cake day: September 24th, 2023

help-circle
rss
  • formatting does depend on the type of variables. Go look at ktfmt’s codebase and come back after you’ve done so…

    I skimmed it. It appears to visit the AST of the code and format that, as any formatter does. ASTs have not been type checked.

    Can you give an example?

    it gives you an option, just like if it was an interface. Did you actually try this out before commenting?

    Precisely! It doesn’t know the answer so it has to guess, or make you guess.

    And how often are you naming functions the exact same thing across two different classes without using an interface?

    You mean how often does the same field name come up more than once? All the time obviously! Think about common names like id, size, begin, children, etc. etc.

    I’m sorry, but you clearly haven’t thought this out, or you’re really quite ignorant as to how intellisense works in all languages (including Ruby, and including statically typed languages).

    I’m sorry but you clearly haven’t thought this through, or you’re just happy to ignore the limitations of Ruby. I suspect the latter. Please don’t pretend they aren’t limitations though. It’s ok to say “yes this isn’t very good but I like Ruby anyway”.


  • I think you’re getting a bit confused. How do you know where x’s type is defined and therefore where x.bar is defined if you don’t know what type x is? It’s literally impossible. Best you can do is global type inference but that has very big limitations and is not really feasible in a language that wasn’t designed for it.

    Do you think that formatters for dynamic languages need to know the type in order to format them properly? Then why in the world would you need it to know where to jump to in a type definition!?!

    Not sure if that is a serious question, but it’s because formatting doesn’t depend on the type of variables but going to the definition of a field obviously depends on the type that the field is in.

    Maybe my example was not clear enough for you - I guess it’s possible you’ve never experienced working intellisense, so you don’t understand the feature I’m describing.

    class A:
      bar: int
    
    class B:
      bar: str
    
    def foo(x):
      return x.bar
    

    Ctrl-click on bar. Where does it jump to?





  • Yeah I have yet to really use Deno in anger because so many people are like “but Python exists!” and unsurprisingly we now find ourselves with a mess of virtual environments and pip nonsense that has literally cost me weeks of my life.

    Though if you’re using Numpy that source like “proper work” not the infrastructure scripting we use Python for so I probably would go with Rust over Deno. I don’t know of mature linear algebra libraries for Typescript (though I also haven’t looked).

    IMO probably the biggest benefit of Rust over most languages is the lower number of bugs and reduced debugging time due to the “if it compiles it probably works” thing.


  • that’s a tough sale to the product team

    Sounds like you’re not the boss enough!

    I agree Rust has a pretty steep learning curve so it’s definitely reasonable to worry about people learning it, especially existing employees. Though I don’t really buy the “easier to hire people” argument. There are plenty of Rust developers actively looking for Rust jobs, so I suspect you get fewer candidates but the ones you do get are higher quality and more interested.

    But anyway I don’t think that argument holds for Deno. Typescript is in the same difficulty league as Python. Anyone that knows Python should be able to transition easily.



  • I’ve literally never heard anyone say that

    Well you didn’t listen then. Google the phrase.

    I can tell you’ve literally never even tried this…

    I do not need to try it to know that this is fundamental impossible. But I will try it because you can go some way towards proper type knowledge without explicit annotations (e.g. Pycharm can do this for Python) and it’s better than nothing (but still not as good as actual type annotations).

    It’s also much more readable than bash, python, javascript, etc. so writing a readable (and runnable everywhere)

    Bash definitely. Not sure I’d agree for Python though. That’s extremely readable.




  • You’re talking about rails.

    Maybe other Ruby code is better, but people always say Rails is the killer app of Ruby so…

    Use an IDE like I said and you can literally just “Find all usages” or “Jump to declaration”, etc.

    That only works if you have static type annotations, which seems to be very rare in the Ruby world.

    In any case, you shouldn’t be using any of these for large projects like gitlab, so it’s completely inconsequential.

    Well, I agree you shouldn’t use Ruby for large projects like Gitlab. But why use it for anything?







  • I can give you some basic Python set-up advice (which is hard-won because nobody tells you this stuff):

    1. Use pyproject.toml, not requirements.txt. It’s better and it’s the recommended way.
    2. Always use type annotations. I saw you used it a bit - well done! But just use it everywhere. Add declarations & type annotations for your class member variables. You’ll thank me later! Also prefer Pyright to Mypy; it is far far better (and the default for VSCode).
    3. I would recommend using Black to autoformat your code. It’s easily the best Python formatter. You can automate it using pre-commit.
    4. ALWAYS PUT MAIN IN A FUNCTION. You should not run any code at a global scope. Do it like this:
    def main():
      ...
    
    if __name__ == "__main__":
        main()
    

    There are two reasons:

    1. Generally it’s good to keep variables to the smallest scope possible. Putting everything in a global scope will just mean people start using it in their functions, and then you have a mess.
    2. Any code you put in a global scope gets run when you import a module. Importing a module should not have any side effects.

    Other minor things:

    1. Path has a crazy/neat override of the / operator so you can do Path("foo") / "bar" / "baz.txt".
    2. Don’t use assert for stuff that the user might reasonably do (like not choosing a background image). assert is meant to be for things that you know are true. You are asserting them. Like “hey Python, this is definitely the case”.
    3. TK is an ancient shitty GUI toolkit. I would recommend QT instead (though it will probably be more pain to set up).


  • That’s not really true. C# and Java are reference-based, uses GC and can be multithreaded, and are very comparable to Rust/C++/C performance. Certainly no more than twice as bad. Whereas Python is probably 50x as bad.

    The real answer is that Python developers have deliberately avoided worrying about performance when designing the language, until maybe 2 years ago. That means it has ended up being extremely dynamic and difficult to optimise, and the CPython implementation itself has also not focused on performance so it isn’t fast.

    But I agree the aim of offering C/C++ speed is never going to be met with Python syntax.