Recent

Author Topic: Why I got F in C  (Read 4038 times)

Tz

  • Jr. Member
  • **
  • Posts: 54
  • Tz with FPC Pen Cil
Why I got F in C
« on: April 12, 2019, 06:57:25 pm »
Why ?

while learning Go https://blog.golang.org/gos-declaration-syntax

in C
   int x;
   <-----
   declares x to be an int

in Pascal
   x: Integer;
   ----------->
   x is integer

In Pascal is simple as aunt ADA say.

while in C, I read left from right at the same time
I have to find x and int from rigth to left,
as if I have to learn English and Arabic.

and worse http://c-faq.com/decl/spiral.anderson.html
have to spin my head, ouch!

uncle Bob say colon : is a noise,  while GO remove it for brevity
we can embrace it, but have to change our behaviour.

just move colon closer to type

   x    :Integer;

so x become clear, and colon become is, we can read it without a pause

   x    :Integer;  // x is Integer
   x    int           // x <pause> int

read it for your self

Code: Pascal  [Select][+][-]
  1. var
  2.    // read with is
  3.    IsOK:    Boolean;
  4.    C:       Char;
  5.    Flag:    Byte;
  6.    ID:      Integer;
  7.    Name:    String;
  8.    Amount:  Double;
  9.  
  10.    // variable name become clearer
  11.    IsOK     : Boolean;
  12.    C        : Char;
  13.    Flag     : Byte;
  14.    ID       : Integer;
  15.    Name     : String;
  16.    Amount   : Double;
  17.  
  18.    // less noise maybe ?
  19.    IsOK     :Boolean;
  20.    C        :Char;
  21.    Flag     :Byte;
  22.    ID       :Integer;
  23.    Name     :String;
  24.    Amount   :Double;
  25.  
  26.    // read without is
  27.    IsOK     Boolean
  28.    C        Char
  29.    Flag     Byte
  30.    ID       Integer
  31.    Name     String
  32.    Amount   Double         // do you mean double the amount ?
  33.  


Ow man, F is fundamentally wrong.


dbannon

  • Hero Member
  • *****
  • Posts: 3723
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Why I got F in C
« Reply #1 on: April 13, 2019, 05:59:05 am »
 :)

just wait until they start teaching you perl.

(personally, I like to the colons line up vertically, whitespace on either side. Sign of an tidy mind)
Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

Handoko

  • Hero Member
  • *****
  • Posts: 5524
  • My goal: build my own game engine using Lazarus
Re: Why I got F in C
« Reply #2 on: April 13, 2019, 07:55:52 am »
I know how great Pascal is. But telling how good Pascal is, by mentioning how bad the others are ... is not cool.

Tz

  • Jr. Member
  • **
  • Posts: 54
  • Tz with FPC Pen Cil
Re: Why I got F in C
« Reply #3 on: April 13, 2019, 08:18:13 am »
 :D luckily Pascal is my first language, when encounter with C, it is harder for me. 

well is just a fact learn from golang and other for example generic.

 :)

jamie

  • Hero Member
  • *****
  • Posts: 7587
Re: Why I got F in C
« Reply #4 on: April 13, 2019, 03:10:41 pm »
There are some parts of C I like, most of which are few but it would be nice if ObjFpc could integrate them..

I like the Verbose structure of Pascal which is why I my self decided on it years ago. Too much single character symbolization in
C language but it does not mean I  can't code in it, I can.
 
 But like I said there are somethings nice about it like the auto inc/dec += which fpc does support.

 I also like how Boolean is done in C to a point, but not fully. I think fpc should have a restricted subset of it..
The only true wisdom is knowing you know nothing

lainz

  • Hero Member
  • *****
  • Posts: 4741
  • Web, Desktop & Android developer
    • https://lainz.github.io/
Re: Why I got F in C
« Reply #5 on: April 13, 2019, 04:15:59 pm »
I get bad my first c exam because do while in c is not the same as repeat until in Pascal. Looks the same but the break condition is the opposite.

Do
While a > b

Keep executing if a is greater than b

Repeat
Until a > b

Keep executing if a is less than b

And the exam was in paper not actual code but a flow diagram but thinking like in c.

Tz

  • Jr. Member
  • **
  • Posts: 54
  • Tz with FPC Pen Cil
Re: Why I got F in C
« Reply #6 on: April 14, 2019, 11:57:13 am »
When I was a boy, and I was a new bie

int*   ptr;   // its left
int   *ptr;   // its right

C its a same.
Me, left its not right!, right its not left!,  Whyyyyyyyyyyyy ?  :D




munair

  • Hero Member
  • *****
  • Posts: 887
  • compiler developer @SharpBASIC
    • SharpBASIC
Re: Why I got F in C
« Reply #7 on: April 14, 2019, 12:23:48 pm »
I'm currently using Go to develop an interpreter/compiler, just as others use C or C++ to develop another language.

Go has features from both C and Pascal but in my opinion is easier to learn and more strict than C. Also, Go does not support classes, but it does have interfaces. I particularly like the (often mandatory) type assertion feature.

Regarding type declarations, one language puts emphasis on the type while others put emphasis on the identifier. Both approaches are legitimate, although admittedly, C's approach can make things harder to read.

Personally, I believe the colon declaration is more clear.
« Last Edit: April 14, 2019, 12:35:41 pm by Munair »
It's only logical.

Thaddy

  • Hero Member
  • *****
  • Posts: 18764
  • To Europe: simply sell USA bonds: dollar collapses
Re: Why I got F in C
« Reply #8 on: April 14, 2019, 12:41:33 pm »
In C int * ptr;   // it's in the middle... is also valid. :D :D :D Even int*ptr is valid (no spaces at all.)
In both Pascal and C whitespace is ignored.
« Last Edit: April 14, 2019, 01:24:10 pm by Thaddy »
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

munair

  • Hero Member
  • *****
  • Posts: 887
  • compiler developer @SharpBASIC
    • SharpBASIC
Re: Why I got F in C
« Reply #9 on: April 14, 2019, 01:54:34 pm »
In C int * ptr;   // it's in the middle... is also valid. :D :D :D Even int*ptr is valid (no spaces at all.)
In both Pascal and C whitespace is ignored.

In the language I'm developing white space is also ignored. Even with references  ;) :

Code: Text  [Select][+][-]
  1. type TPoint of
  2.   x: ushort
  3.   y: ushort
  4.   z: ushort
  5.   New: func
  6. end
  7.  
  8. TPoint . New = function(x:ushort, y:ushort, z:ushort): TPoint do
  9.   var p: TPoint
  10.   p . x = x
  11.   p . y = y
  12.   p . z = z
  13.   return p
  14. end
  15.  
  16. var p: TPoint
  17. p = p .   New(7, 5, 12)
  18.  
  19. print(p . x, p  .  y, p.z)

It is a logical result of ignoring white spaces by the lexer. Disallowing white spaces would lead to extra checking, thus slower parsing.
« Last Edit: April 14, 2019, 04:57:41 pm by Munair »
It's only logical.

Thaddy

  • Hero Member
  • *****
  • Posts: 18764
  • To Europe: simply sell USA bonds: dollar collapses
Re: Why I got F in C
« Reply #10 on: April 14, 2019, 03:31:37 pm »
Well, your language is also not Python  :P
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

munair

  • Hero Member
  • *****
  • Posts: 887
  • compiler developer @SharpBASIC
    • SharpBASIC
Re: Why I got F in C
« Reply #11 on: April 14, 2019, 03:52:35 pm »
Well, your language is also not Python  :P
I sure hope it isn't.  :D
It's only logical.

Tz

  • Jr. Member
  • **
  • Posts: 54
  • Tz with FPC Pen Cil
Re: Why I got F in C
« Reply #12 on: April 14, 2019, 05:36:48 pm »
Do you know zWick ?

zWick is a man of ... focus ... commitment ... sheer will ...
rumors said he is programming in outer space with FPC
With the FPC pencil .... Who can do programming like that

and so me in FPC with not so focus just a bit commitment and share testing
 
ptr :^int;  ptr^ := value;   
   
// ^type left var^ right ... testing stereo sound ...

Sounds good    :D

bytebites

  • Hero Member
  • *****
  • Posts: 778
Re: Why I got F in C
« Reply #13 on: April 14, 2019, 06:39:47 pm »

Repeat
Until a > b

Keep executing if a is less than b


Should it be: Keep executing if a is less or equal than b?

lucamar

  • Hero Member
  • *****
  • Posts: 4217
Re: Why I got F in C
« Reply #14 on: April 14, 2019, 07:56:36 pm »
Repeat
Until a > b

Keep executing if a is less than b

Should it be: Keep executing if a is less or equal than b?

Yes. Good catch :)
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

 

TinyPortal © 2005-2018