News for hackers. Stuff that matters.
Re:Ask HN: Programs that saved you 100 hours? (2022 edition) by nx7487 on Tuesday December 20, 2022 @03:12PM (#34071811)
sed -i "s/function_name/function_name2/g" $FILES && git restore $FILES

Edit: Not claiming this is better, just saying what I get by with. I have never used an IDE in my career so far, or any autocomplete or code modification features.

Re:Ask HN: Programs that saved you 100 hours? (2022 edition) by eitland on Tuesday December 20, 2022 @03:17PM (#34071874)
It cannot differentiate between a field in a class and a variable in a method, or even a word in a comment, can it?
Re:Ask HN: Programs that saved you 100 hours? (2022 edition) by P5fRxh5kUvp2th on Tuesday December 20, 2022 @03:20PM (#34071913)
add the c and it will prompt so you can make the determination yourself.
Re:Ask HN: Programs that saved you 100 hours? (2022 edition) by monkpit on Tuesday December 20, 2022 @08:36PM (#34075590)
So, no
Re:Ask HN: Programs that saved you 100 hours? (2022 edition) by P5fRxh5kUvp2th on Wednesday December 21, 2022 @04:10AM (#34078345)
People get so hung up on this, but it's literally the shallowest sort of refactoring. If you're choosing your tools strictly for this you're doing yourself a disservice.
Re:Ask HN: Programs that saved you 100 hours? (2022 edition) by eitland on Wednesday December 21, 2022 @05:41AM (#34078961)
It is also the simplest refactoring, and my point is no command line tricks I have can seen can even reliably do this.

Refactoring support in modern IDEs goes far beyond renaming public fields and methods.

Re:Ask HN: Programs that saved you 100 hours? (2022 edition) by P5fRxh5kUvp2th on Wednesday December 21, 2022 @06:14AM (#34079181)
I've had this exact conversation so many times over the years.

In truth, you just don't know the tools that well. And that's ok, but as someone who does and regularly does these things in both IDE's and in vim, you're wrong.

But I'm not going to bother trying to convince you, the same way I'm not going to try and convince you that my gf of 11 years is pretty awesome. I don't need you to get better to know that you're wrong.

Re:Ask HN: Programs that saved you 100 hours? (2022 edition) by eitland on Wednesday December 21, 2022 @10:05AM (#34081575)
Good for you. 17 years since I met my gf here.

And I started on vim a long time before IntelliJ :-)

Re:Ask HN: Programs that saved you 100 hours? (2022 edition) by casey2 on Tuesday December 20, 2022 @03:52PM (#34072373)
Sam could do all that since the 80s. So ~40 years.
Re:Ask HN: Programs that saved you 100 hours? (2022 edition) by ajuc on Tuesday December 20, 2022 @05:05PM (#34073358)
It can with a proper regex. Mostly. Depending on the language, your patience, and the amount of false positives you are comfortable with.

I did sth like that (I had bash scripts for common programming "refactorings" and "queries" like "print all classes and methods where this variable is used"). I couldn't use a modern IDE cause we were programming on a legacy linux server through ssh for licencing reasons.

And the (C++) code was written by a guy that learnt C++ and OOP on the job and it showed. Class hierarchies were sometimes 8 levels deep and class variables were reused for different purposes to "save effort on serializing them" :)

So if the user interactions were in the same order and with the same text prompts - a class would inherit them and add some new ones. Even if the old class was just accidentally asking the user similar questions :) So OR_PalNr could mean shelf number in base class and Printer number in descendant, because both times the user was asked to "scan the barcode", while the callstack was a mix of methods from both classes :)

Fun times.

BTW nowadays I mostly work with IntelliJ, but sometimes a script is still the best way to understand the code. For example grepping the git blame output is often very useful. It's never 100% reliable, but it's often good enough.

Re:Ask HN: Programs that saved you 100 hours? (2022 edition) by eitland on Wednesday December 21, 2022 @02:07AM (#34077562)
First:

> BTW nowadays I mostly work with IntelliJ, but sometimes a script is still the best way to understand the code. For example grepping the git blame output is often very useful. It's never 100% reliable, but it's often good enough.

I see we are on the same page : )

> It can with a proper regex. Mostly. Depending on the language, your patience, and the amount of false positives you are comfortable with.

For everyone else: in any of the three big Java IDEs, and in a number of other cases, you don't need much patience or tolerance for false positives, at least if your code isn't too unreasonable (with any sufficiently expressive language you can of course always fool it by somehow accessing things dynamically).

> I did sth like that (I had bash scripts for common programming "refactorings" and "queries" like "print all classes and methods where this variable is used"). I couldn't use a modern IDE cause we were programming on a legacy linux server through ssh for licencing reasons.

This is awesome!

Re:Ask HN: Programs that saved you 100 hours? (2022 edition) by geysersam on Tuesday December 20, 2022 @03:19PM (#34071909)
Sure, but if function_name is a subword of another_function_name, this would break things :/
Re:Ask HN: Programs that saved you 100 hours? (2022 edition) by knighthack on Thursday December 22, 2022 @08:01PM (#34101097)
Why would you want to avoid autocomplete?

And what language do you code in?