News for hackers. Stuff that matters.
Re:Castle Engine – free, os, x-platform, 2D/3D game engine u... by mirpa on Monday February 19, 2024 @07:55AM (#39429236)
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.
Re:Castle Engine – free, os, x-platform, 2D/3D game engine u... by andsoitis on Monday February 19, 2024 @08:18AM (#39429422)
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!');
Re:Castle Engine – free, os, x-platform, 2D/3D game engine u... by logicprog on Monday February 19, 2024 @09:25AM (#39430031)
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.
Re:Castle Engine – free, os, x-platform, 2D/3D game engine u... by FpUser on Monday February 19, 2024 @11:18AM (#39431449)
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;
Re:Castle Engine – free, os, x-platform, 2D/3D game engine u... by darkwater on Monday February 19, 2024 @10:37AM (#39430914)
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.
Re:Castle Engine – free, os, x-platform, 2D/3D game engine u... by FpUser on Monday February 19, 2024 @11:07AM (#39431312)
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.
Re:Castle Engine – free, os, x-platform, 2D/3D game engine u... by dennis2354 on Monday February 19, 2024 @12:17PM (#39432208)
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!');
Re:Castle Engine – free, os, x-platform, 2D/3D game engine u... by vrruiz on Monday February 19, 2024 @11:13PM (#39437995)
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');