Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

The /prog/matic programmer

Name: Anonymous 2012-09-27 15:16

ANyways, so... I was reading The Pragmatic Programmer [1] and it occurred to me that we should probably boil these principles down for the novices amongst us. ITT things you want to carve into your colleagues' faces.

* KEEP IT FUCKING SIMPLE, MOTHERFUCKER!
* You're code is not ``clever'', it is autistic.
* Code is /not/ poetry or art. Go away! Fuck your OCD.
* This shit has been solved a thousand times over.
* You do not need to design with the latest and greatest in gang-of-four approved OOP design patterns, using infinitely scalable NoSQL solutions in hip new languages that compile down to JavaScript (srsly WTF?!), just to create a CRUD application.
* Not everyone gets off on code, some of us just want to make a living doing the least amount of effort that is required to deliver a consistent quality for an extended period of time.

I swear by god if I see one more AbstractControllerFactoryInterface

[1] http://pragprog.com/the-pragmatic-programmer, easily found online.

Name: Anonymous 2013-05-13 10:27

>>64
So I've read through all of the answers, and it looks like your real problem is files with individual lines stretching beyond 4GiB, or 16EiB, or whatever, which would mean that your catch is `you better not store each line in an array as you read it in.'  Okay, fine.  That gets rid of >>20.

Another possible issue you're having is that the trivial file '' is not numbered correctly.  I.e.

foo
bar
baz
quux


should become

1 foo
2 bar
3 baz
4 quux
5


?  I don't agree with this myself for religious reasons, but I think it's something you might do, as it eliminates pretty much everyone and fits with your desire to say `the PROBLEM SPACE!' as you point out, smugly, that an empty sequence of 0 bytes is a valid line.  Then the exiting of >>34 would also be caused by the specific (EOF != (c = getchar())) segment, though the problem with it is `it exits too fast' instead of `it uses in-comparison =' or `it assigns char/int wrong' as everyone has been assuming.

It hasn't been you specifically who complains about I/O buffers being arrays, so I'll assume getchar and putchar are fine.  That means that if I don't do anything stupid like readline and make sure to number correctly, this should fit your (poorly-communicated) requirements:

#include <stdio.h>

int main(void)
{
  unsigned int ln = 2;
  int i;

  printf("1 ");
  i = getchar();
  while (i != EOF) {
    putchar(i);
    if (i == '\n') printf("%u ", ln++);
    i = getchar();
  }

  return 0;
}


As a final note, you should rephrase the question to point out that the line numbers must be correct, as 0 is a perfectly valid decimal integer that can be prepended to all lines.  You should also clarify that this need not be done in place, if that is truly your intention.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List