News for hackers. Stuff that matters.
Re:What programming languages are used most on weekends? by Cyph0n on Tuesday February 07, 2017 @10:19PM (#13595400)
Isn't that just a `grep -R [regex pattern]`? Not sure where something like awk or sed fits in to solve such a problem.
Re:What programming languages are used most on weekends? by sokoloff on Tuesday February 07, 2017 @10:28PM (#13595447)
The primary point was one of mindset, but the second example in the cited section is a tailor-made sed example:

Let's say you're on my team, and I've decided I'm a real stickler for code formatting. But I've got peculiar tastes, and one day I decide I want to have all parentheses stand out very clearly in your code.

So let's say you've got a set of source files in C, C++, or Java. Your choice. And I want you to modify them so that in each source file, every open- and close-paren has exactly one space character before and after

Re:What programming languages are used most on weekends? by dgacmu on Tuesday February 07, 2017 @10:46PM (#13595541)
Y'know - after thinking about it a little, I'd argue that this is a question that could serve a second purpose. The obvious out-of-the box implementations of this in sed/perl/etc. would all fail to properly handle open and close parens in strings and comments. Particularly multi-line comments and strings with escaped quotation marks inside of them.

I like sed. I like perl one-liners. I would consider it a mistake to try to do this on a real codebase in a batch manner with just a regexp. You'd be far better off googling to find a source code formatter that includes a real parser, like clang-format.

Re:What programming languages are used most on weekends? by sokoloff on Tuesday February 07, 2017 @11:06PM (#13595656)
The question specification is such that you don't need special handling of comments, strings, etc. "every paren" isn't qualified as "that is part of the code".

The point of the question is more to gauge your understanding of/familiarity with available tools and ability to think laterally rather than immediately jump to "I've got to write some real code to solve this"

Re:What programming languages are used most on weekends? by kriro on Wednesday February 08, 2017 @02:28AM (#13596510)
I'd probably reach for ANTLR to write a quick parser since working with such a stickler is likely to require more code formatting changes in the future.

As an aside, the stuff I used sed/awk for in the past have pretty much been replaced by Python for me. These days it's pretty rare to not have a default Python install on any Unixy box one spins up and in the rare cases I use Windows I tend to install Anaconda so it's also slightly more cross-platform for my use cases.

Re:What programming languages are used most on weekends? by Cyph0n on Tuesday February 07, 2017 @10:43PM (#13595529)
Whoops, didn't notice that one. Thanks for linking that post by the way. Great read.
Re:What programming languages are used most on weekends? by sokoloff on Tuesday February 07, 2017 @11:06PM (#13595660)
Most Yegge blog rants are well worthwhile, IMO. I wish he wrote more of them.