12 ms·
This! I sometimes wonder if JS programmers know that with C#/VS you can just change the name of a class, and without doing anything else (not even replacing),
by _zamorano_ 7y ago
This!
I sometimes wonder if JS programmers know that with C#/VS you can just change the name of a class, and without doing anything else (not even replacing), all involved names just change, and everything works 100%, without writing any test.
And the same goes for moving a method to another class, or renaming member variables, modules, files... everything just works and is instantaneous.
To me, not being able to aggresively refactor withour worrying something will break somewhere is like backwards and old school (in the bad way)
When a project evolves, a class, a struct... grows and suddenly a name, perfectly fine at the beggining, does not make sense any longer. With C#/VS you just change and 2 seconds later you're still working.
- STRiDEX 7y agorenaming a class in vscode works in js and ts via typescript language service.
- _zamorano_ 7y agoHonest question: By "works" you mean you have 100% guarantee nothing will break nowhere?
- treve 7y agoEdge cases exist. I'd assume that Java and c# will also have edge-cases when things like reflection come into play.
- Filligree 7y agoCertainly, but reflection is almost never used. I don't think I've touched a single real-life codebase where it would get in the way in this manner. The same can't be said for languages like JS.
- smhinsey 7y agoEven reflection is going to vary based on your IDE. If you use ReSharper or Rider, a safe rename refactoring will locate and optionally update string references as well. I don't know if VS itself has adopted this feature.
- Filligree 7y agoIDEA does the same thing. It's amazingly useful, even if you don't use reflection -- variable names end up in comments and documentation as well, all of which it will offer to change.
- ken 7y agoI’ve never touched a “real life” code base in a static language (including C#) where this wouldn’t be an issue. C# is not a sufficiently high level language that I can avoid duplication without the use of reflection.
- dehrmann 7y agoPeople try to avoid reflection like the plague, most use cases don't depend on a hard-coded method/class name, and the ones that do can sometimes be detected by tools. It's pretty rare to run into this, and the one of two times I did something horrible like this, I wrote a test for it and made if fail loudly because what I was doing was brittle (by Java standards) and unexpected.
- ehnto 7y agoSome might be surprised to know that in modern PHP this is also the case. The whole point of all the typing and structure is so you and the IDE can sanely reason about and understand the structure of the code. If I get code and all of a sudden not even my IDE knows what's going on, it clues me in that there are layers of indirection in the codebase I'm going to have to waste time reading into, like magic methods or loose typing.
- rdevsrex 7y agoYep, PHPStorm is a memory hog, but man is it handy in catching errors I didn’t think of.
- cosmotic 7y agoIs it really a memory hog? I'm using IDEA, PHPStorm's more fully featured Java IDE (That also loads PHP code!) ; I have 6 projects open right now, including a PHP project, some java projects, some ruby, groovy, etc; I have 20 files open, numerous plugins enabled, and all sorts of connections to databases and tests; it's been running for days it's using 500MB. Both PHPStorm and IDEA are written in Java (they share a common code base). Don't confuse [Java eagerly allocating memory from the operating system but then not using it for anything (yet)] with java using a lot of memory. For speed, java allocates memory it anticipates using in the future. This lets it manage it's own memory without involving the operating system and thus context switches. If you start using a lot of other applications and available system memory starts running low; java will detect this and relinquish the pre-allocated memory it's not using.
- toolz 7y agoI sometimes wonder if IDE users realize you can do 99.9% of the same things with simple tools. Personally I don't want my editor magically updating the codebase because there will be edge cases and I don't want magic happening in the background when those edge cases arise. In practice I'm sure the class name change has likely not given you issues in a long time or maybe ever, but that doesn't mean edge cases don't exist and when they happen to someone it can be at the worst times and add significant troubleshooting to an unrelated problem. edit: further learning those simple tools has a more generic application to other problems while the IDE magic will likely go until there's an issue to be understood and you're depriving yourself of learning generally applicable tooling to trade a slight inconvenience for magic that has the potential to cause great inconvenience and once that magic from the IDE bites you and you learn how it works - you've learned something with no general application to other problems. edit2: since I can't reply in-line jcelerier - I _could_ do that with CLI tooling and depending on the language it would be trivial. However, I would _never_ do that because changing the method/function name to suit my context would be very unlikely to avoid making other code less readable. That's a huge anti-pattern that your IDE is making easy. Further, consider the implications for language design when making language design decisions that require a specific type of IDE magic to be considered a reasonable language design decision. I have a hard time believing relying on the IDE lock-in is good for the community of that language. philwelch - I genuinely don't know the answer, but what happens when you change a class name -> forget you do it before saving the file -> go to another file and try to change the class name there but have a typo -> go back to the original file and save the change? I would bet the typo'd change goes unchanged and now you're left scratching your head since that magic has always worked before.
- tsss 7y agoObviously you don't have much experience with IDEs and statically typed languages, which is a shame because they make our life so much easier. There are no edge cases. And even if there were the IDE can show you the refactoring and you can decide on a case-by-case basis. > what happens when you change a class name -> forget you do it before saving the file -> go to another file and try to change the class name there but have a typo -> go back to the original file and save the change? A good IDE does not care if you save the file or not. It is always up-to-date. Renaming a class in just one file is also impossible, since the IDE will do refactorings atomically over the whole project. But lets just assume you somehow managed to fuck it up that badly (things can always go wrong): You will still realize your error almost instantly because a statically typed language does not defer such checks to runtime. The program wouldn't even run anymore. By far the biggest issue with automatic refactoring is accidentally renaming stuff in comments (or forgetting to do so) because I'm too lazy to look at every single place. But find&replace has the same problems.
- deleted 7y ago[deleted]
- Gaelan 7y agoI think you can do all those things with typescript and any decent IDE.
- edflsafoiewq 7y agoIs this really true? The hard part of renaming a class isn't usually changing the name Foo -> Bar, it's finding all the variables with type Foo named stuff like result_foo and renaming them result_bar. Can it help with that?
- dnautics 7y agoStatic typing can help with a lot of things but it can't fix this error: pub fn add(a: i64, b: i64) i64 { return a - b; }
- maxdamantus 7y agoActually, it kind of can: https://tryidris.herokuapp.com/compile#YWRkIDogSW50IC0+IEludCAtPiBJbnQKYWRkIGEgYiA9IGEgLSBiCgphZGRUZXN0IDogYWRkIDQgNSA9IDkKYWRkVGVzdCA9IFJlZmw= https://tryidris.herokuapp.com/compile#YWRkIDogSW50IC0+IElud... The above link refers to the following Idris code: add : Int -> Int -> Int add a b = a - b addTest : add 4 5 = 9 addTest = Refl
- reitzensteinm 7y agoThat unit test would be just as easily implemented with dynamic typing.
- deleted 7y ago[deleted]
- exitheone 7y agoyes, intellij for java will also rename all local variables and all mentions of the class in comments.
- edflsafoiewq 7y agoHow exactly does that work? How does it decide what variables to rename and what to rename them to?
- ulshv 7y agoIt is possible for JS/TypeScript as well in VS Code. Works really well.
- z3t4 7y agoRefactoring by renaming things is like renovating a house by painting it in another color. I like to refactor using a wrecking ball.
- maremp 7y ago> I sometimes wonder if JS programmers know that with C#/VS you can just change the name of a class How exactly does this knowledge help? I know this is possible and I do miss it. But it's extremely diffcult to support it in JS because of how the languages works. VSCode tries, but it's still limited. So should we all switch to writing C#? You can't avoid writing JS if you want to create a web app. There are tools to avoid it, but one has to know what's under the hood or they'll have a bad time. TypeScript is doing great progress on this part, and it supports easy refactors, but it's still lacking in some parts, for example the type inference is still poor when it comes to complex cases and the type declarations depend on will of maintainers.