News for hackers. Stuff that matters.
Re:Generating a Java program with 90% less code by _zamorano_ on Wednesday December 04, 2019 @12:04PM (#21704011)
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.

Re:Generating a Java program with 90% less code by ehnto on Wednesday December 04, 2019 @12:13PM (#21704146)
Some 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.

Re:Generating a Java program with 90% less code by rdevsrex on Wednesday December 04, 2019 @02:58PM (#21706275)
Yep, PHPStorm is a memory hog, but man is it handy in catching errors I didn’t think of.
Re:Generating a Java program with 90% less code by cosmotic on Wednesday December 04, 2019 @04:01PM (#21706920)
Is 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.

Re:Generating a Java program with 90% less code by toolz on Wednesday December 04, 2019 @12:17PM (#21704212)
I 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.

Re:Generating a Java program with 90% less code by jcelerier on Wednesday December 04, 2019 @12:25PM (#21704352)
> I sometimes wonder if IDE users realize you can do 99.9% of the same things with simple tools

I'd really like you to show me how you can refactor e.g. a method called "write" in a 500+kloc codebase in less than 5 seconds with "simple tools". With any C++ ide from the last decade it's basically a keyboard shortcut + typing the new name + fixing the few remaining compilation errors that may have cropped up in generic code. With sed & al ? good luck, see you in a few weeks.

Re:Generating a Java program with 90% less code by jstimpfle on Wednesday December 04, 2019 @01:24PM (#21705219)
> I'd really like you to show me how you can refactor e.g. a method called "write"

I'm not taking sides on the issue discussed here, but regarding this quote... This is one of the biggest reasons I don't do OOP. Using plain functions with slightly longer but globally unique names so many issues go away.

And the biggest issue is that I can't read a code base if so many function names are not unique and possibly not conveying enough information for local understanding. That style always requires the reader to carry so much context in their head, to be able to resolve the "polymorphism" to concrete implementations. (Yes, in a proper IDE we can jump to the implementation interactively with a few keypresses, but it's still much harder to read).

Re:Generating a Java program with 90% less code by wrmsr on Wednesday December 04, 2019 @01:58PM (#21705659)
Java interface methods do have globally unique* names when fully qualified, but nobody types the full thing out because namespacing is good. It is neither expected nor even desirable for readers or authors to keep resolutions of interface implementations in their heads - that would defeat the purpose of interfaces.

* jar-hell (and dll-hell) aside

Re:Generating a Java program with 90% less code by jstimpfle on Wednesday December 04, 2019 @03:18PM (#21706462)
There is a difference between interfaces and abstract interfaces. It is very helpful to know if all calls to the same function/method resolve to the same implementation. Method syntax always suggests that their could be arbitrarily many implementations.
Re:Generating a Java program with 90% less code by ka0lin on Wednesday December 04, 2019 @04:51PM (#21707549)
> Using plain functions with slightly longer but globally unique names so many issues go away.

That makes me assume two things: you work alone and your projects don't exceed 5.000 (fivethousand) lines of code. Without some namespacing and an expected method length less than 100, more likely 10 lines than 90 or more, you end up with roughly 160 names. An average human knows 150 people, maybe by their name. And while you have friends or at least parents and grandparents occupying some of the »address sace« few of your methods will not be »at hand« for your brain.

And in case you already prefix your methods with something like io_write(...), db_query(...) and you hand in context-specific references like io_write with a sort of file handle and db_query with a sort of database connection I transform all this 1:1 in an OO-style language and back.

Re:Generating a Java program with 90% less code by jstimpfle on Thursday December 05, 2019 @07:42AM (#21711823)
Your assumption is wrong (of course), and yes, I don't doubt that it's always possible to make a rewrite in a shitty way, and then convert it back.

For a clearer description of what I mean, see my other comment below where I write two lines of code in both ways.

Re:Generating a Java program with 90% less code by pjmlp on Wednesday December 04, 2019 @01:46PM (#21705499)
> Using plain functions with slightly longer but globally unique names so many issues go away.

Only on monolith code bases without any signs of modularity.

Re:Generating a Java program with 90% less code by jstimpfle on Wednesday December 04, 2019 @03:07PM (#21706360)
Oh, don't get me wrong, I'm not against abstract interfaces where they make sense. What I'm against is using underqualified names for stuff that has a statically resolveable implementation.

In other words, don't make it look complicated before it actually is.

Re:Generating a Java program with 90% less code by pjmlp on Thursday December 05, 2019 @02:06AM (#21710522)
Even on that case, with good modularity on C code (TU == module), there will be plenty of hidden symbols and some indirection (function pointer) going on, and not a pile of global symbols.

That was kind of the gist of my comment.

Re:Generating a Java program with 90% less code by jstimpfle on Thursday December 05, 2019 @05:31AM (#21711296)
You did't understand what I was saying.

    foo.log(xyz);
    bar.log(42);
vs

    log_event(foo, xyz);
    log_event(bar, 42);
Provided that both approaches do the same, which is more clear? It is the second one, because it clearly suggests that there is no polymorphic switching based on foo/bar.

Wading through non-trivial projects, pervasiveness of the first approach makes me nervous, because I'm told at every occasion, "don't even try to understand what's going on in the system globally. We .log(), shouldn't that be enough for you to know?".

While the second approach is calming to me, "You see, we have this simple logging system, where everything ends up being written to. It's not that complex after all, and if you want to know what's going on you can just jump directly to the log_event()" function.

Yes, by asserting that foo and bar are of the same type, and asserting that the .log() method is not virtual, I can reach the same conclusion. But that's the point, it requires work that you can't practically do if each line of code contains a method call. There is no mincing words, you're using the wrong syntax...

Re:Generating a Java program with 90% less code by pjmlp on Thursday December 05, 2019 @08:33AM (#21712098)
Ok, but you are betting on false hopes then.

First foo or bar can be function pointers.

Or maybe log_event is a macro whose behavior depends on the environment. And I have used some crazylogging ones back in the 2000's when coding C, that would even dump the current state of the process alongside its parameters.

Or then again, log_event() plugs into a configurable logging system and one cannot predict its behavior just from the call site, even when using the same types.

Finally if we move away from C semantics, maybe log_event is overloaded or is doing multiple dispatch, thus the two calls, depending on the argument types, are not going to land on the same implementation.

Re:Generating a Java program with 90% less code by jstimpfle on Thursday December 05, 2019 @09:40AM (#21712568)
> First foo or bar can be function pointers. Or maybe log_event is a macro whose behavior depends on the environment.

Then different uses of the same identifier still resolve to the same implementation, and make the IDE jump to the same location, etc.

(I acknowledge that everything can be something else. And in theory you can redefine macros to have uses of the same identifier resolve to different implementations. Etc, etc. I'm sure you know about the IOCCC. But here we talk about good programming practice. It's a good practice not to suggest something complicated while the reality is simple. There's no argument to win here.)

> Finally if we move away from C semantics, maybe log_event is overloaded or is doing multiple dispatch, thus the two calls, depending on the argument types, are not going to land on the same implementation.

Which is why I do not use C++, or at least avoid most of its features. For me, it's all about clarity and reducing number of moving parts. It's not a contest in making complicated things that pretend to be simple. And it's not a contest in making simple things that look complicated. And it's not a contest in reducing the number of characters in individual identifiers at all costs.

Re:Generating a Java program with 90% less code by jcelerier on Thursday December 05, 2019 @11:40AM (#21713717)
> It is the second one, because it clearly suggests that there is no polymorphic switching based on foo/bar.

so, question : suppose you have your log_event, and now your bosses comes and tells you that the client needs to have two additional different logging mechanisms - say, to journald and to some websocket log server. The system can log to either of your three logging mechanisms at any point through changing a configuration somewhere in a GUI but you also need some core classes to always be logged through journald no matter the state of the rest of the system.

How do you update your design to reflect that ?

Re:Generating a Java program with 90% less code by r-w on Thursday December 05, 2019 @02:24PM (#21715490)
You change it. Better to change a nice solution than to keep adding small chunks to an already complex one. https://en.wikipedia.org/wiki/You_aren%27t_gonna_need_it
Re:Generating a Java program with 90% less code by jstimpfle on Thursday December 05, 2019 @03:40PM (#21716229)
Exactly this. This answer needs to be so much more popular. "What if the requirements change" is such a common and such a wrong question.

What is needed in the face of changing requirements is actually this: lean structure with few dependencies that can be adapted.

Re:Generating a Java program with 90% less code by jstimpfle on Thursday December 05, 2019 @03:50PM (#21716336)
I might change log_event() to log to a facility depending on the configuration, and make another function log_core_event() that has the special logging implementation, and change the core modules to call log_core_event() instead. (gee, it's a simple text replace!). This way you can actually see what happens without any indirection.

That wasn't hard.

Re:Generating a Java program with 90% less code by jcelerier on Friday December 06, 2019 @02:22AM (#21719863)
but now you also have to change every log_event(x) to log_event(configuration, x), and pass the log configuration as an argument in literally every function of your code (you would not want to use a global prone to thread initialization issues if you have multiple threads doing logging on startup, right ? :-) )

Also you've made your logging library project-specific by making a log_core_event function. Thanks but I'll keep using spdlog in my projects, which do not need newcomers to learn about your log_core_event, what is a core module and what is not, just to be able to write the three functions they are called for in that project !

Re:Generating a Java program with 90% less code by jstimpfle on Friday December 06, 2019 @03:24AM (#21720070)
That's kinda moving goalposts since the configuration seemed to be a given. In any case, I don't see a problem with global variables. Otherwise, the threading of the configuration (and other context) I assume to have existed before that little change.

That all has nothing to do with virtual methods.

> thread initialization if you have multiple threads doing logging on startup, right ? :-) )

There is no technical difference between "global" and "local" variables. It's merely a syntactical difference.

If you run into concurrency problems with global variables, you'll run into problems just as well with objects. Unless you make multiple objects. In which case, you could also have done thread-local storage, no?

In the end, it's much clearer to me to use global variables (TLS or not) since this way I can actually see the data relations. If there is just one instance of a thing, why would I pass it around as objects? It's not going to help understandability.

> Also you've made your logging library project-specific by making a log_core_event function.

That doesn't make sense. Can't I just add another function without breaking everything? Note that I probably wouldn't even add this function to "the logging library" but to the core modules...

> what is a core module and what is not

If you prefer having everything switched behind your back, resulting in unreadable and unintelligible source code... you do you.

More technical notes...

If you don't like the presence of two or more functions for logging, then why not have an explicit context argument? You call log_event(MODULE_FOO, foo, xyz) instead, and the log_event function implements all the plumbing logic in a central place, easily understood (Most logging approaches do that, I think. They have "facility" and "severity" arguments). This approach seems much more preferable to me compared to an implementation that you can't see locally, and that can't be influenced locally. What would you do if we go for the OOP approach with a virtual method, and now call into a different module that would need a different logger?

If having a dynamically switched implementation was really what we want to do, there is no problem with doing that. My post was just about using method syntax for static things, which I think harms readability.

Re:Generating a Java program with 90% less code by jcelerier on Friday December 06, 2019 @05:07AM (#21720477)
> In any case, I don't see a problem with global variables.

well, that cuts short to the discussion. There are plenty of places & coding standards where those are outright forbidden.

> If you prefer having everything switched behind your back, resulting in unreadable and unintelligible source code... you do you.

we have very different notions of readable. For me the less stuff I have to read and the more readable it is - I just want my code to be the pure domain problem and could not give a rat's ass about how logging or networking or whatever is implemented if those aren't my domain.

> Can't I just add another function without breaking everything?

that does not break the code but that breaks Joe intern's mental model and expectations of anyone who will think that log_* functions are from the same library

> then why not have an explicit context argument?

and here we are, reinventing OOP by hand in C. There is literally no difference between log_event(context, ...) and context.log_event(...) - but you get better tooling :

* completion -for the first I'd most certainly end up typing the full name if there are a lot of l-started functions while for the second I'd type c<shortcut>.l<shortcut><enter> and only see the few relevant functions in the autocompletion list) etc... in the second.

* namespacing - if I want to see all the logging functions available I can just click on "context" and my IDE will happily show me all the available methods in a panel and nothing else. With C functions, well, I have to scroll in a list of 150000 functions. And also wonder (& have to explain) why log_event() is in <util/logger.h> and log_event_core is in <core/core_logger.h>.

* split implementations - if at some point you want to port your software to, say, an arduino without network capabilities (talking literally forom past experience here), the monolithic log_event function now becomes an #ifdef HAS_NETWORK / #ifdef HAS_JOURNALD / ... mumbo-jumbo. While with multiple logger subtypes it's just a matter of changing your build system to not compile the unavailable implementations, without even needing to change the code (or change a list of types in a header if you use static polymorphism instead).

> What would you do if we go for the OOP approach with a virtual method, and now call into a different module that would need a different logger?

dependency injection ? modules can request either for a default logger which will be sourced from the gui configuration, or whatever specific logger they actually need due to functional requirements.

Besides, I still don't see the readability problem with virtuals. Again in my IDE if I want to see "what happens" I press F2 on context.log_event and it displays me the list of all the possible implementations if it isn't able to determine that one is used statically at that point. And I much prefer to read three five-lines email_logger::log, journald_logger::log, websocket_logger::log functions than a pile of if/else's.

Re:Generating a Java program with 90% less code by jstimpfle on Monday December 09, 2019 @06:04AM (#21741704)
> HAS_NETWORK / #ifdef HAS_JOURNALD / ... mumbo-jumbo. While

But when I had a glance at the project you linked on github, that was basically the first thing I found there...

A suggestion that I have there would be to use the linker instead (make different source files based on implemntation / existance of an implementation). This way you can eliminate most of the #ifdefs.

Regarding dependency injection, I don't see a practical difference to just using global variables / global functions, apart from the fact that by convention DI gives you back objects with virtual implementations, which I don't like.

I won't go into the rest of the things you said because we pretty much discussed it all.

Re:Generating a Java program with 90% less code by r-w on Thursday December 05, 2019 @02:21PM (#21715463)
It seems like your problem isn’t with OOP, but with generics. (You would like Go.)
Re:Generating a Java program with 90% less code by tsss on Wednesday December 04, 2019 @12:53PM (#21704759)
Obviously 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.

Re:Generating a Java program with 90% less code by philwelch on Wednesday December 04, 2019 @12:21PM (#21704274)
With a statically typed language and an IDE this isn’t a real issue. There’s no “edge case” when you rename a class or method symbol in a Java project because the IDE deterministically knows what are the invocations of the same symbol.
Re:Generating a Java program with 90% less code by TeMPOraL on Wednesday December 04, 2019 @01:33PM (#21705321)
Except when you use reflection. Or code generation tooling that tends to crop up around DI frameworks.

Yes, in general, the ability of IDE to make these kind of large-scale changes quickly, reliably and mostly bug-free is nice. But I rarely miss it in languages where it's impossible.

It may be that one of the ways your language shapes your code is the way you structure it. For instance, in my Lisp codebases, I can hardly think of any place where Java-style automated refactoring could be useful; in the current largish codebase I work on, it rarely is the case that constructs introduced in one file are used directly in more than one or two other files - which makes refactoring entirely doable with a dumb text editor, and Java-like automated refactoring wouldn't save all that much time over doing a regex search and manually visiting every line listed in results.

Re:Generating a Java program with 90% less code by r-w on Thursday December 05, 2019 @02:25PM (#21715510)
What types of program are you writing?
Re:Generating a Java program with 90% less code by philwelch on Friday December 06, 2019 @02:08PM (#21724964)
I would expect that Lisp programming wouldn't derive much benefit from an IDE.
Re:Generating a Java program with 90% less code by addicted44 on Wednesday December 04, 2019 @01:21PM (#21705176)
Unless you're using something like .Net remoting (or the Java equivalent), and now suddenly everything breaks.

Or you have a larger codebase split up into multiple .Net solutions and DLLs where code is referenced through the generated DLLs.

The refactor looks great, until it starts breaking things for the many consumers of your code.

In fact, the latter is a situation where simple text tools will make life a lot safer and easier than whatever the IDE does (which pretty much will be limited to the bounds of the .sln file, whereas a simple text tool operating over files in the entire codebase will alert you to the fact that this is being used elsewhere).

My argument isn't to claim that simple text tools are better at refactoring. They aren't. However, I've run across several situations where we've had issues in a massive codebase because developers believed that refactoring was as easy as hitting the Refactor button in Visual Studio, and everything will work magically.

The belief in programming 'magic' (whether through IDEs or frameworks that abstract a ton) without understanding what those tools actually do is what I'm worried about. Use IDEs to do what you need to by all means, but it's much better when you actually understand what it's doing before doing something with it.

Re:Generating a Java program with 90% less code by philwelch on Wednesday December 04, 2019 @02:54PM (#21706227)
> Or you have a larger codebase split up into multiple .Net solutions and DLLs where code is referenced through the generated DLLs.

Sure--and to be fair, I've never worked in .Net much. But if you're changing the package interface, you should arguably do so in a backwards-compatible fashion anyway, depending on how your stuff actually gets built and deployed. If everything's contained in the same repo and you can't refactor across multiple components in the same repo, that sounds like a problem.

> The belief in programming 'magic' (whether through IDEs or frameworks that abstract a ton) without understanding what those tools actually do is what I'm worried about. Use IDEs to do what you need to by all means, but it's much better when you actually understand what it's doing before doing something with it.

Agreed!

Re:Generating a Java program with 90% less code by arbie on Wednesday December 04, 2019 @12:30PM (#21704425)
What if the IDE did not traverse a specific file during the global search and replace?

Are you relying on a correct and comprehensive project/workspace setup within the IDE?

Re:Generating a Java program with 90% less code by this_user on Wednesday December 04, 2019 @12:52PM (#21704747)
So your argument is that something might, in some extremely rare cases, go wrong, and that is why you'd rather do it the manual way? That's basically like a carpenter refusing to use power tools, because they might, theoretically, explode.
Re:Generating a Java program with 90% less code by Sharlin on Wednesday December 04, 2019 @12:38PM (#21704543)
> Are you relying on a correct and comprehensive project/workspace setup within the IDE?

Of course. Not much point in using an IDE otherwise.

Re:Generating a Java program with 90% less code by philwelch on Wednesday December 04, 2019 @02:55PM (#21706238)
> Are you relying on a correct and comprehensive project/workspace setup within the IDE?

That's not something I "rely" on, it's the first thing I make happen whenever I use an IDE.

Re:Generating a Java program with 90% less code by chosenbreed37 on Wednesday December 04, 2019 @01:21PM (#21705167)
> What if the IDE did not traverse a specific file during the global search and replace?

You generally get compilation/build errors highlighting the bits that were missed (for whatever reason)

Re:Generating a Java program with 90% less code by pavel_lishin on Wednesday December 04, 2019 @12:49PM (#21704702)
Then your tests catch it, and you have to fix a single file manually, instead of a dozen or a hundred or a thousand.
Re:Generating a Java program with 90% less code by ken on Thursday December 05, 2019 @10:03AM (#21712810)
Sure, and that’s exactly the same failure mode as “sed”. What’s the benefit of the big IDE?
Re:Generating a Java program with 90% less code by pavel_lishin on Thursday December 05, 2019 @10:12AM (#21712903)
> What’s the benefit of the big IDE?

To quote myself, "fix a single file manually, instead of a dozen or a hundred or a thousand".

And what happens when you need to rename, say, a method name that's also used as a variable name in many places? xWhat happens if multiple classes define the same method name, but you only want to rename that method for a single class?

Yes, you can probably do it in sed. If you're used to it enough, you can probably do it pretty quick, with sufficient regexps that you only have to debug a few times.

Or you can right click or hit CMD-. or hit F2 or whatever with your cursor on a method name, type in the new name, wait 2 seconds, and you're done.

Re:Generating a Java program with 90% less code by gmueckl on Wednesday December 04, 2019 @12:41PM (#21704590)
Given the truly excellent quality of refactoring toolsets like Resharper for C# I'd wager that you're more likely to miss an edge case with your manual approach than with the tools. The tools can reliably differentiate between methods of the same name in different classes at the call sites (or between different classes with the same name in different namespaces). They will search comments and strings for occurrences of the name in question and prompt you with a nicely formatted overview dialog box which ones to adjust.

The tools are at a point where I'm usually breaking my code when I'm doing manual refactoring, but never when I let the tools do the job.

Re:Generating a Java program with 90% less code by nec4b on Thursday December 05, 2019 @02:34AM (#21710605)
IDEs are not magical. They understand your code because they use compilers to parse it, therefore they can also reason about it at a higher level than a simple text editor or CLI tool which treat your code as nothing but characters.
Re:Generating a Java program with 90% less code by z3t4 on Wednesday December 04, 2019 @03:10PM (#21706393)
Refactoring by renaming things is like renovating a house by painting it in another color. I like to refactor using a wrecking ball.
Re:Generating a Java program with 90% less code by STRiDEX on Wednesday December 04, 2019 @12:09PM (#21704087)
renaming a class in vscode works in js and ts via typescript language service.
Re:Generating a Java program with 90% less code by _zamorano_ on Wednesday December 04, 2019 @12:13PM (#21704151)
Honest question: By "works" you mean you have 100% guarantee nothing will break nowhere?
Re:Generating a Java program with 90% less code by treve on Wednesday December 04, 2019 @12:30PM (#21704412)
Edge cases exist. I'd assume that Java and c# will also have edge-cases when things like reflection come into play.
Re:Generating a Java program with 90% less code by Filligree on Wednesday December 04, 2019 @12:45PM (#21704649)
Certainly, 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.

Re:Generating a Java program with 90% less code by smhinsey on Wednesday December 04, 2019 @01:32PM (#21705315)
Even 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.
Re:Generating a Java program with 90% less code by Filligree on Friday December 06, 2019 @11:23AM (#21723206)
IDEA 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.
Re:Generating a Java program with 90% less code by ken on Thursday December 05, 2019 @10:00AM (#21712784)
I’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.
Re:Generating a Java program with 90% less code by dehrmann on Friday December 06, 2019 @12:18AM (#21719453)
People 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.
Re:Generating a Java program with 90% less code by maremp on Thursday December 05, 2019 @01:32PM (#21714852)
> 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.

Re:Generating a Java program with 90% less code by ulshv on Wednesday December 04, 2019 @02:11PM (#21705818)
It is possible for JS/TypeScript as well in VS Code. Works really well.
Re:Generating a Java program with 90% less code by Gaelan on Wednesday December 04, 2019 @01:25PM (#21705235)
I think you can do all those things with typescript and any decent IDE.
Re:Generating a Java program with 90% less code by edflsafoiewq on Wednesday December 04, 2019 @02:09PM (#21705792)
Is 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?
Re:Generating a Java program with 90% less code by dnautics on Wednesday December 04, 2019 @02:16PM (#21705863)
Static 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;
    }
Re:Generating a Java program with 90% less code by maxdamantus on Wednesday December 04, 2019 @02:51PM (#21706199)
Actually, it kind of can:

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
Re:Generating a Java program with 90% less code by reitzensteinm on Wednesday December 04, 2019 @03:02PM (#21706320)
That unit test would be just as easily implemented with dynamic typing.
Re:Generating a Java program with 90% less code by exitheone on Wednesday December 04, 2019 @03:04PM (#21706330)
yes, intellij for java will also rename all local variables and all mentions of the class in comments.
Re:Generating a Java program with 90% less code by edflsafoiewq on Wednesday December 04, 2019 @05:05PM (#21707712)
How exactly does that work? How does it decide what variables to rename and what to rename them to?