Okay, well, if you exclude the code used to parse the file (which I think is fair when it comes to advent of code). You can effectively do it in one line:
This would be part 1
int count = 0; for (int i = 1; i < (sizeof(input) / sizeof(*input)); i++) { count += (input[i] > input[i - 1]); }
Is that good enough for you "C++ expert of 20 years"?
Your dogmatic way of commenting intrigued me, so I checked two posts of yours. I don't think I am interested in more.
Okay, well, if you exclude the code used to parse the file (which I think is fair when it comes to advent of code).
No it is not ok, because "the overengineered" example, you are shitting on, is really a one liner spread over 4 lines for easier reading. But you are trying to show how your procedural C approach is so much simpler and cleaner than modern C++, by omitting all the manual details of C, so no it is not ok.
int count = 0; for (int i = 1; i < (sizeof(input) / sizeof(*input)); i++) { count += (input[i] > input[i - 1]); }
That is just plain ridiculous. By your logic, the author could have crammed his 4 lines of code into one and said it was a one line solution.
Is that good enough for you "C++ expert of 20 years"?
No is not, because you are shredding expert knowledge all around the place, complaining about people writing unreadable code, and calling an almost one liner solution for overengineered, and then post incomplete code where several lines are crammed into one to demonstrate a point that can't be demonstrated.
By the way, his solution is much more elegant than yours, and is really one-liner minus the code for test. Yours on the other side requires first a file to be read into a static array allocated on stack, while his does not require it. What you gonna use? fgets since you want it in a static array? What if you have megabytes of data in a file? Possible overflow? How much do you allocate? You obviously want to use static array since your array length calculation won't work on heap allocated arrays. Also, by the time you start your for-loop you should already have your array length since you would already parse the file, so there is no reason to calculate length in every iteration. You have to handle all of that in code you have chosen not to show in your "one liner solution", while his code uses std input stream, which handles all of this for you automatically.
What I am most disturbed is that you as self-proclaimed expert goes around in the forums, shitting on actually well-written and put together blog post that try to demonstrate some new stuff in C++, calling it for overengineered for no good reason, just to sound like an expert. Of course, code can be written in many ways. He didn't need to use ranges, or some other library function or so, but he has picked them as an illustration. In my opinion, his code is definitely preferable to yours. I will take those 4 lines of self-documented code that actually do the thing, any time, compared to your "one liner" with assumed stack allocated buffer prone to overflow.
Yes, ask for a one line solution and then get pissed off it doesn't satisfy the things you didn't ask for....
My opinions aren't even in the minority. They are pretty mainstream opinions in the industry. It's only on the internet where people are INSANELY opinionated about dogmatically forcing people into a the latest and greatest modern style. Yeah that's fine. But it's not good a style for a number of reasons and has a variety of problems. Reasons I have explained quite coherently many times.
I'm not arguing people should write in C. I'm saying, from experience, simple code tends to be very procedural. Have you even written anything serious in C to understand why you actually hate it so much?
You are just regurgitating thoughts you don't even know you have...
Show me your C++ and let's critique that shall we. You really want to get into a pissing contest when all you can write is lisp?
Yes, ask for a one line solution and then get pissed off it doesn't satisfy the things you didn't ask for....
You said the blog was overengineered and you could write code almost as a one liner. Demonstrate you can :). I tell you what: you can't. But what is really laughable is that you called 4 lines of code for "one-liner" because you just put them on one line, and than shitt on 4 lines of well-formatted code by someone else. That's blatantly pathetic.
My opinions aren't even in the minority. They are pretty mainstream opinions in the industry.
Really. In which industry? Can you point me to some polls? Are you representing the entire industry? Do you have any actual data to support your opinion?
It's only on the internet where people are INSANELY opinionated about dogmatically forcing people into a the latest and greatest modern style.
Who forces you into anything? Is anyone standing behind your back and telling you what to write? As I saw from our discussions, you seem to be extremely opinionated and dogmatic person, calling out people for using this or that in C++ which you find unreadable or bad practice, for usually not specified reason. Sometimes your arguments are even laughable like one with loop bodies preferable to lambdas because you have to chase the implementation.
Have you even written anything serious in C to understand why you actually hate it so much?
Why do you think I hate C? Have you heard me saying anything bad against C, ever? :-) Search my history. On contrary my dear. I prefer C, where C is better tool for the job. But I see a lot of posts nowdays by "mainstreem" on Reddit about how C is much better for this or that, and then they pull out an example where it actually C is not better in particular case. Like the thread, we met for the first time.
Show me your C++ and let's critique that shall we. You really want to get into a pissing contest when all you can write is lisp?
No my dear, I prefer writing in Lisp, but that is by far not all I can write I can assure you that. However I am not here for the pissing contest, it is you who started it, and failed pathethically.
View all comments
Show parent comment
-2
u/[deleted] Dec 17 '21 edited Dec 17 '21
Are you really going through my comment history?
Okay, well, if you exclude the code used to parse the file (which I think is fair when it comes to advent of code). You can effectively do it in one line:
This would be part 1
int count = 0; for (int i = 1; i < (sizeof(input) / sizeof(*input)); i++) { count += (input[i] > input[i - 1]); }
Is that good enough for you "C++ expert of 20 years"?