3 ms·
> I changed some variable names and I had to chase down all the places they were referenced, $ find . -name '*.c' -exec perl -i -pe 's/\btheOldName\b/theNew
by sgbeal 17d ago
> I changed some variable names and I had to chase down all the places they were referenced,
$ find . -name '*.c' -exec perl -i -pe 's/\btheOldName\b/theNewName/g' \{} \;
- sfn42 17d agoAny half decent IDE will change them automatically for you, no need to chase them down. Just look at the git diff if you want to see where things changed.
- donkey_brains 17d agoYeah this is a very very common and fundamental operation in programming. Always use the “refactor” tool in your IDE instead of trying to change every instance of a variable name by hand. It’s like using a linter: you do it because it’s the right thing to do and doing it without the tool confers no benefit and is prone to error.
- sgbeal 17d ago> Always use the “refactor” tool in your IDE instead of trying to change every instance of a variable name by hand. That _is_ the refactoring tool in my IDE (emacs). i demonstrated replacing _all_of them at once, not replacing them each by hand. > ... because it’s the right thing to do and doing it without the tool confers no benefit and is prone to error. There was nothing in my post done "without the tool." Shell/find/perl _is_ the tool for C refactoring, and has been for decades.
- exceptione 17d ago> i demonstrated replacing _all_of them at once, not replacing them each by hand. Not really, that is search and replace. IDE's do typesafe refactoring. If you change the Find method in class A, you should only change occurences of x.foo(), where x has type A. You shouldn't accidentally change all B.find()'s. That is my advice for everyone completing their first Python tutorial: learn a typed language next if you aspire to do serious work. It also saves you writing many manual tests that you had to make otherwise, as the compiler makes that superfluous. Plus your IDE becomes a superpower.
- trencedamp 17d agoI normally would use find replace in vscode but I either forgot that existed or I was enjoying myself too much
- sgbeal 17d ago> Any half decent IDE will change them automatically for you, no need to chase them down It's long been my experience that that only works with high-level languages (specifically, those with bytecode), not C (especially once symbols are generated from macros). (OTOH, i've not touched an IDE in well more than 10 years.) Also, it's long been my experience that any half-decent IDE is still a pale shadow of Emacs.
- eudamoniac 17d ago> It's long been my experience...i've not touched an IDE in well more than 10 years It's long been that your experience is outdated. A modern IDE will refactor C code just fine, and emacs is a pale shadow of a proper IDE. I understand you are proud to be using an old tool and doing things "the old fashioned way" but you are just using an objectively worse tool for this thing you're talking about throughout the thread. Find and replace is not the correct way to rename a method or variable for obvious reasons.
- dunefox 17d agoNot using an IDE in 2026?
- sgbeal 17d ago> Not using an IDE in 2026? Emacs. Uninterrupted since the 1990s.
- dunefox 16d agoI'm sure you can run an IDE on EmacsOS.
- trencedamp 16d agoI actually use vscode but I've not used find replace for months so I forgot how