Thread: Pascal and Indentation

  1. #1
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547

    Pascal and Indentation

    Quote Originally Posted by Adak View Post
    Naw, like the song says:

    "Life will never be, exactly like you want it to be..."
    ... Mamas and the Papas
    LOL... OK.

    Thing is I've been tagged on indentation so often I think they finally gave up. As I've explained before I come from a Pascal background where source formatting is very different and, so far, I've not been able to break the habit... so my source always looks like Pascal with C keywords.

    So, yes, I do in fact know what that feels like....

    Aside: Last night I found myself once again wondering if there is a pascal compiler out there that can handle windows headers but isn't totally b__tardized by VCL, OOP and RAD... In it's purely procedural form Pascal is a great language, it's almost "C with strings" and I wouldn't mind getting back to it someday. Anybody up for an Open Source compiler project?
    Last edited by CommonTater; 12-19-2010 at 09:16 PM.

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    I haven't seen that with Pascal. Most of the code examples showing an algorithm that I've seen have been in Pascal, and they're always showing great indentation.

    Wait until you run into Python -- ho, ho, ho! Indentation is absolutely critical!

    I thought there was a Free Pascal or Turbo Pascal compiler and IDE for it, out there, no?

    I liked Pascal, except for all the writelines. My experience with it amounted to helping my nephew write one program, for his college class, a decade ago. It was Turbo Pascal and it had an incremental compiler that was SO FAST to use. Even on my laptop, it compiled like a bat outta hell.

    Wurth gave Pascal some smart features (like their strings). I never quite figured out why he left it to go on to some other language. Or, why Pascal didn't become more popular in programming, beyond academia.

    I wouldn't have a clue how to program a compiler. Or do you mean something that takes the Pascal code and changes it into it's equivalent in C and then uses a C compiler on that code?

  3. #3
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Adak View Post
    I haven't seen that with Pascal. Most of the code examples showing an algorithm that I've seen have been in Pascal, and they're always showing great indentation.
    Well, ok... maybe I've invented my own style and now I can't uninvent it... LOL.

    In any case I think you've seen how I write source... I've been doing it that way for so long I find other formatting hard to read.


    Wait until you run into Python -- ho, ho, ho! Indentation is absolutely critical!
    I have no intention of doing that.

    I thought there was a Free Pascal or Turbo Pascal compiler and IDE for it, out there, no?
    Free Pascal is an incomplete Delphi clone and buggy as all git.
    Turbo Pascal is 16 bit.

    I'm thinking "just plain Pascal" 32 and 64 bit flavours and a nice set of headers and libs for windows.

    I liked Pascal, except for all the writelines. My experience with it amounted to helping my nephew write one program, for his college class, a decade ago. It was Turbo Pascal and it had an incremental compiler that was SO FAST to use. Even on my laptop, it compiled like a bat outta hell.
    Yep... and no linking phase... straight from source to executable. Most often in a single compiler pass too...

    There are 3 things I really liked about Pascal...
    1) Real Strings (use = < > != etc. on strings!)
    2) NOT case sensitive
    3) Units allowed real easy scoping of functions and variables.

    Sigh... Maybe we should look at creating a C extension???

    Wurth gave Pascal some smart features (like their strings). I never quite figured out why he left it to go on to some other language. Or, why Pascal didn't become more popular in programming, beyond academia.
    Blame Borland. They were the world leaders with Pascal. They licensed up and then did the Turbo Pascal thing for a few versions (I still have copies on floppies someplace) then all of a sudden they announced a major breakthrough in "Object Oriented Programming", dropped all Pascal development, totally butchered the compiler and went on to introduce "Delphi"...

    Wurth, reportedly threw his hands up in defeat and walked away. Oberon was his short lived successor to Pascal, but by then the whole mess was too far gone. Pascal was a dead horse.

    I once took a Delphi Distro and got the underlying Pascal and libraries out from under it, hacked up the Run Time Libraries a bit and got it to re-compile itself... Wrote a few small programs just to check it out, but by then they had it so screwed up I never did get it to work properly.

    I wouldn't have a clue how to program a compiler. Or do you mean something that takes the Pascal code and changes it into it's equivalent in C and then uses a C compiler on that code?
    Ummm no... If I wanted to do that, I'd just program in C... Which is what I'm up to and why.

    (BTW... if you'd like to continue this maybe we should get a Mod to split the thread....)

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by CommonTater
    (BTW... if you'd like to continue this maybe we should get a Mod to split the thread....)
    This thread was split from Very easy issue with strstr.

    Quote Originally Posted by CommonTater
    Thing is I've been tagged on indentation so often I think they finally gave up.
    Generally, I think that your indentation itself is fine. What I find unusual and problematic for editing is your brace placement, but I rarely edit a copy of your code anyway.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by laserlight View Post
    This thread was split from Very easy issue with strstr.
    Thanks for moving this laserlight, it was pretty far off topic where it was.

    Generally, I think that your indentation itself is fine. What I find unusual and problematic for editing is your brace placement, but I rarely edit a copy of your code anyway.
    Oddly I never did that in pascal... a comparison of "my way"...

    Code:
    // in C
    int Double(int x)
      { return x * 2; }
    
    // in Pas
    integer Double(integer x)
       begin
         return x mul 2;
       end
    Go figure....


    Anyway the thing that's really on the plate here is Pascal itself... It's a shame to see a good language die, and this one has. I'd still be interested in helping write a Pascal compiler....

    Well, either that or a C extension that is not case sensitive and has real strings...

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    I remember when Borland came very close to going under in the dot com crash, combined with the continued popularity of MS C++. Although Pascal was good, it was looking like yesterday's newspaper, compared to to the OOP languages.

    Checking out Googles Go language, I was struck by how modern (easily concurrent, with garbage collection), and flexible it was, and safe. Compiler is a real ripper, as well! Looking at Go, it's hard to see a reason for Pascal to be re-done.

    It's a bit like species with these languages. You don't like to see it, but some species are never designed well enough to last. They're too specialized, like the Saber-tooth tiger, or too slow and small, like the Dodo bird. Small flightless birds that can't run fast, are doomed to be an easy dinner when predatory mammals appear in the environment.

    Rather than put a lot of work into re-creating Pascal, you might want to look into something that has a lot more potential:
    The Go Programming Language

    The lack of classes is refreshing, strings are fully supported, and numbers are just numbers - no longs, no floats, and full arbitrary precision. You want 50 decimal places on that number, you got it, built right in.

    Not as complete as more established languages, but it's simple, concise, and very modern. I can see where you could be quite productive with that language, especially in a multi-server type environment, where communication between servers is so prevalent.

    I haven't used it yet, but I'm considering becoming a Go, fan boy!

    What do you think of it?

  7. #7
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Quote Originally Posted by CommonTater View Post
    Free Pascal is an incomplete Delphi clone and buggy as all git.
    Turbo Pascal is 16 bit.

    I'm thinking "just plain Pascal" 32 and 64 bit flavours and a nice set of headers and libs for windows.
    Indeed you'll have to roll out your own. Unfortunately you will removing features from Windows programming, rather than adding to it. The problem is that Windows development is centralized around the concept of OOP. Delphi emerged exactly to cover that ground and there's a reason why it became more popular than Pascal ever did.

    Since Pascal and C are so close to each other, you could leave type of development for C, instead. A Pascal compiler which aim is to remove OOP, and to offer a strict Windows API implementation stripped down of any other standard windows libraries, can only serve pascal syntax aficionados. And you must agree this is a weak argument for adoption.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  8. #8
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Mario F. View Post
    Indeed you'll have to roll out your own. Unfortunately you will removing features from Windows programming, rather than adding to it. The problem is that Windows development is centralized around the concept of OOP. Delphi emerged exactly to cover that ground and there's a reason why it became more popular than Pascal ever did.

    Since Pascal and C are so close to each other, you could leave type of development for C, instead. A Pascal compiler which aim is to remove OOP, and to offer a strict Windows API implementation stripped down of any other standard windows libraries, can only serve pascal syntax aficionados. And you must agree this is a weak argument for adoption.
    Hi Mario,
    I don't know if you've looked at my current freeware offering or not but it was written entirely in PellesC...from the Windows API level... partially because I really do like C programming and partly to make a point with a couple of "coder" friends... If you look at the exes in that project you will discover none is over 200k and these are some of the largest programs I've written in C. I seriously doubt you could provide the same functionality in less than 2 or 3 megabytes with Java or Delphi... 234 in .Net.

    I suppose at some point I'm going to have to make the leap to C++ and manage to get my head around it but right now and for reasons I am wholly unable to explain OOP simply will not sink in between these ears.... and, believe me, it's not for the lack of trying.

    Std. Pascal has it's advantages over C ... Type and Range checking for one thing. Stricter scoping rules for another. Private functions inside other functions. The "units" concept, very like C libraries, offers some strong modularizing potential. Of course a native string type carries it's own weight. There are things to recommend Pascal over C. Or, I should say, there *were* things to recommend it before Borland got into the game.

    But you're point is taken, implementing a new Pascal compiler will be largely a "one off" done for personal interest at this point. Despite it's advantages Pascal does seem to be little more than an intellectual toy.

  9. #9
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Adak View Post
    I remember when Borland came very close to going under in the dot com crash, combined with the continued popularity of MS C++. Although Pascal was good, it was looking like yesterday's newspaper, compared to to the OOP languages.
    Pascal was around for quite a while before C++ showed up. It had a pretty good run.

    Checking out Googles Go language, I was struck by how modern (easily concurrent, with garbage collection), and flexible it was, and safe. Compiler is a real ripper, as well! Looking at Go, it's hard to see a reason for Pascal to be re-done.
    The Go Programming Language
    I will check it out as soon as I get a quiet day to set it up and play with it. Apparently I have to download half the compilers on earth and several specialized libraries to get it to work, so I won't be doing that without some quiet time on my hands.

    I've also looked at D, Oberon, and others. But, since Pascal was killed I've always found myself back at C, wishing for the features I've mentioned already...

  10. #10
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by CommonTater
    But you're point is taken, implementing a new Pascal compiler will be largely a "one off" done for personal interest at this point. Despite it's advantages Pascal does seem to be little more than an intellectual toy.
    Sounds like fun except that I, uh, never understood a whole lot of stuff from (the newer version of) the dragon book, and have forgotten like half of what I understood
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  11. #11
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by laserlight View Post
    Sounds like fun except that I, uh, never understood a whole lot of stuff from (the newer version of) the dragon book, and have forgotten like half of what I understood
    I haven't heard the Dragon Book mentioned in many years... wow, major nostalgia...

    Amazon.com: Compilers: Principles, Techniques, and Tools (2nd Edition) (9780321486813): Alfred V. Aho, Monica S. Lam, Ravi Sethi, Jeffrey D. Ullman: Books

    Way over my head at the time... maybe still is.

    But yes, it would be a very interesting challenge...

  12. #12
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    639
    If you haven't written one before then go for it because you'll probably learn something. If you have then it's really more of the same with slightly better engineering because of what you learned the first time. That's just me though, YMMV.

    As a start, look at the Crenshaw compiler articles. I think they implement a Pascal compiler in straight C. I can't remember the specifics but it's a decent introduction.

  13. #13
    Registered User
    Join Date
    Jul 2007
    Posts
    131
    I wouldn't recommend Crenshaw articles to anyone. I think starting with something which provides good background and good implementation would be better, I don't think Crenshaws provide either of those.

    I wouldn't recommend Dragon book either. Even in "new edition" you can see it's aging and lacking (SSA in like 2 pages?).

    This is what I would recommend.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Very easy issue with strstr
    By rkrajnov in forum C Programming
    Replies: 8
    Last Post: 12-20-2010, 12:49 AM