Hacker News new | past | comments | ask | show | jobs | submit login

Oh, really?

  if ((input = 'y') or (input = 'Y')) then
    begin
      writeln ('blah blah');
    end
  else if ((input = 'n') or (input = 'N')) then
    begin
      writeln ('blah');
    end
  else
    begin
      writeln ('Input invalid!');
    end;

  if input == 'y' || input = 'Y'
  {
      writeln ('blah blah');
  } else if input = 'n' || input = 'N'
  {
      writeln ('blah');
  } else
  {
      writeln ('Input invalid!');
  }
If you find Pascal easier to read, I would guess you have very special set of eyes.



Your example isn't idiomatic. You would not write begin/end for single-line cases.

Instead it would be:

  if ((input = 'y') or (input = 'Y')) then
    writeln ('blah blah')

  else if ((input = 'n') or (input = 'N')) then
    writeln ('blah')

  else
    writeln ('Input invalid!');

OR even better

  case uppercase(input) of 
    'Y': writeln('blah blah');
    'N': writeln('blah');
  else
    writeln('Input invalid!');


Well if we're doing that, then you wouldn't use the curly brackets in the C style syntax example either. If you just make one ideomatic without making the other ideomatic, the comparison ceases to be fair. Anyway, doing that to both of them would make the comparison pointless, because the point wasn't to compare ideomatic code examples, but to compare the syntax in a general case, so writing them slightly unideomatically to show off the general-case syntax is fine, as long as both are written the same way to control for unrelated variables (like special-case syntactic sugar), which is precisely what the original comparison did: write both code samples in the most general way, and crucially in the same way, so we could directly compare the scanability of syntax. And imo C won by a mile.


you are also allowed:

  case input of
    'A'..'C': writeln('blah blah blah');
    'N','n': writeln('blah blah');
    'Y','y': writeln('blah');
  else
    writeln('Input invalid!');
  end;


TBH? I see them basically the same. My brain probably scans equally faster "b...n" and "e..d" then the direction of the curly brace. And I haven't read or written Pascal since early high-school, ~30 years ago.


Your example is not Pascal problem. It is inability of an author to come up with clean looking version. One can do bad style in any language.


Great example. Your C-Code translated to Pascal would be

  if (input = 'y') or (input = 'Y') then
  begin
    writeln ('blah blah');
  end
  else if (input = 'n') or (input = 'N') then
  begin
    writeln ('blah');
  end
  else
  begin
    writeln ('Input invalid!');
  end;

Now this does not look any different then your code. Except your code does compile but has several errors.

And why should be the double pipe be any better to read than an "or" statement?

Btw: as you won't need the begin and ends it would look like

  if (input = 'y') or (input = 'Y') then
    writeln ('blah blah')
  else 
  if (input = 'n') or (input = 'N') then
    writeln ('blah')
  else
    writeln ('Input invalid!');


Well, other simpler options are:

  if (input in ['Y', 'y']) then
    WriteLn('blah blah')
  else if (input in ['N', 'n']) then
    WriteLn('blah')
  else
    WriteLn('Input invalid');
And:

  if (LowerCase(input) = 'y') then
    WriteLn('blah blah')
  else if (LowerCase(input) = 'n') then
    WriteLn('blah')
  else
    WriteLn('Input invalid');




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: