• Roger (unregistered)

    What's wrong with this? I did the same thing when I programmed my shopping cart using pure HTML.

  • Greg Miller (unregistered)

    I did the same thing when switching from Pascal to C, but I couldn't imagine someone actually using that in production code. It only makes your code look like Pascal, you still have to know all of the intracies of C to program in it.

  • Darren Walter (unregistered)

    Ok, I have no idea what is wrong with this code. Can someone break it down to me in simple terms? Monosyllabic if possible.

  • Peter (unregistered)

    weee, isn't this anti-pattern called something like "you can write any program in fortran?"

  • Mike (unregistered)

    Speaking of Fortran...I purchased Fortran for Dummies in 24 Hours and now I pull in 100K a year in profit on my eCommerce site. All because it was written in Fortran!

  • Phil Scott (unregistered)

    I did a search for #define void procedure on google and found this link: http://xxxxpro.ru/razn/PASCAL.H

    "This file was written by XXXX Pro to make C++ easier for Pascal ..."

    That's all I could find because our filter blocked domains with XXX in the name. And one could only assume XXXX Pro is some really hard core stuff right there.

  • Sean Kleinjung (unregistered)

    Here's the rest of the file. Wow.

    //This file was written by XXXX Pro to make C++ easier for Pascal programmers.
    #define begin {
    #define end }
    #define Begin {
    #define End }
    #define BEGIN void main() {
    #define END. }
    #define Procedure void
    #define Function
    #define and &&
    #define or ||
    #define not !
    #define shl <<
    #define shr >>
    #define record struct {
    #define then

    typedef integer int;
    typedef shortint short int;
    typedef longint long int;
    typedef byte unsigned short int;
    typedef word unsigned int;
    typedef dword unsigned long int;
    typedef real float;
    typedef string char;
    typedef pointer void*;

  • Jeff S (unregistered)

    It's funny to see things defined as nothing, so they are ignored. Aparently for nice-reading code. This gives me some good ideas; you could do:

    #define please
    #define also
    #define thanks
    #define let

    then you can write code like:

    also please let a = 1 thanks

  • cbane (unregistered)

    > typedef byte unsigned short int;

    And there's another problem here. An "unsigned short int" is 2 bytes long, not 1. For byte, it really should do something like:

    typedef byte unsigned char;

    It also assumes that a "int" is 2 bytes long, when it's actually 4 bytes long on most any modern (32 bit) system. And then there's "typedef string char". Nevermind that C++ already has a string type, to use the "string" from the header file, you'd have to do something like 'string foo[] = "asdf";', which looks like you're creating an array of strings, not one string. There might also be a problem with record, but I'm not familiar enough with PASCAL to know if you need a "begin" before actually defining the elements of a record.

  • bill (unregistered)

    >>>>>>>>>Ok, I have no idea what is wrong with this code. Can someone break it down to me in simple terms? Monosyllabic if possible. <<<<<<<<<
    Horse
    Shit

  • Steve O. (unregistered)

    Personally, the biggest WTF here is how much fun it is going to be to maintain this. A C coder comes into the project expecting C code and instead sees pseudo Pascal. C is hard enough without redefining the keywords.

  • Guayo (unregistered)

    What a bummer... for a moment I thought Pascal.h would rox0r but what the hell is declare fonthandle fh;?
    I want var fh:fonthandle; before the procedure block.
    >(

  • Smartypants (unregistered)

    Kudos for cursing! You're-a-big-kid-now!

  • Factory (unregistered)

    I had a lecturer who did this in uni, erm, he was a complete tool and everyone hated him.

  • Ludvig (unregistered)

    Well spotted guayo! fonthandle is typedefe'd to LOGFONT. The "declare" 'keyword' I have no idea why it's in the code (as with lots of other things). The defines are not cut from the actual header, but the general idea is right.

    I'm still waiting for the other 2 WTF's in this code-snippet to be detected... ;)

  • Ron (unregistered)

    What a beautiful piece of code.

    1. Parameter 'a' is never used.
    2. CreateFontIndirect takes a LOGFONT not a GC.
    3. You can't delete something that has been selected into a GC.

  • AiKay (unregistered)

    um, where is "Integer a" used?

    there is no error checking, CreateFontIndirect might fail..

    does not restore dc (doesnt care about the return from SelectObject)

    its been a while since i have done anything with GDI but u cant delete the object right away can u?

  • G Dawg (unregistered)

    Uh guys, the WTF here is that this dude is selecting something into the DC and then deleting it!! I have no idea what kind of havoc this would cause!!

  • Uriel (unregistered)

    I saw this once in a forum, after that I searched for a way to do it vice-versa. :)
    Failed miserably, though.

  • Harlan (unregistered)

    Hmmm... reminds me of an old learning C book I had which included, I kid you not:

    For readability, we do the following:
    #define .GT. >
    #define .LT. <

    and so on...

  • grunch grunch grunch (unregistered)

    Harlan, that's truly ghastly. But what's with the dots in the #defines?


    AiKay: Uuu urrr urr ururu uruuuuu uru ur ur urrrr?!

    Personally, I recommend English, but if all you can do is grunt frantically, have fun with it.


    http://www.dba-oracle.com/dress_code.htm

    Quoth Burleson, "A fresh haircut, spit-shined shoes and a crisp suit go a long way in establishing a professional demeanor." Um, yeah. Personally, I establish my "professional demeanor" by walking around the office in bare feet, shaving about once a week, and doing my damn job. Maybe if I spit-shined my shoes, I could skip all three and get a sinecure as an Oracle android.

    "People can spot a cheap suit at 300 yards, and so can our clients." Is it just me, or does it sound like he thinks those two categories don't overlap?

    And women must shave their arms -- not pits, the whole arm -- "if required". Okay.

  • markd (unregistered)

    grunch*3 : the dots there for .GT. and .LT. are a FORTRANism. those were the symbols used in FORTRAN for doing greater-than and less-than.

  • Ilya Haykinson (unregistered)

    Speaking of "#define please", there is a language that does actually do that -- Intercal.

    http://www.catb.org/~esr/intercal/

  • StuP (unregistered)

    How much plastic surgery has that Burleson bloke had? (mug shot at top of page) Man... that would be more of a put off than a 'cheap suit'!

  • kevin (unregistered)

    In Intercal, the "please" is important. You have to use the right amount of "please" statements or the compiler will say you are being too rude. If you use too many, it will say you are being too polite.

  • fluffy (unregistered)

    Those size definitions make a lot of sense if it's someone trying to migrate from, say, Turbo Pascal in DOS (which primarily used 16-bit data types) to C in Win32.

    Also, the size of int etc. isn't guaranteed to be 4 bytes. It's platform-dependent. If you want a specific size you're supposed to use the POSIX int_t types (e.g. uint32_t or int16_t or whatever); ANSI C only specifies that 'int' is the size of the native word unit (which can be anything, really), that 'char' is a single byte (and not necessarily an 8-bit byte), a short is bigger than a char, an int is at least as big as a short, and a long int is larger than an int.

    So, in Turbo C++ on DOS and Win16, int was 16-bit, while long int was 32-bit. This leads to some really interesting crap in older Win32 code (from the win32s and early Win'95 days) since a lot of stuff back then had a lot of code which ran in 16-bit mode and some which ran in 32-bit mode - so in some places, an int was 16 bits and in others it was 32.

    Thankfully, the only people who have to deal with that stuff regularly these days are embedded systems programmers, and even then that's going by the wayside thanks to ARM pretty much getting a stranglehold on the entire industry (like, you don't see Z80s in new products very often these days).

  • Pascal User (unregistered)

    Dear users,

    I challenge you all to write a rich text editor in the form of win32 with equivilent features as mine - if you write one smaller than mine or the same size, then I may consider looking into C++ and C. You must do this visually (with a visual tool) in order to be fair.

    You may use assembler embedded in your code if you wish, but your code must mainly show significant amounts of C or C++.

    My Rich Text editor is smaller than Notepad for Win95 .. just to give you an idea. It has more useful features than wordpad, such as on the fly font formatting versus dialog window editing.

    I also challenge you to write the editor in a shorter time period, even considering I am a novice. I challenge advanced programmers that have been coding for more than 15 years.

    I was going to write up some information on why begin and End are important in coding, but instead I'll post something useful: A real man's challenge, to actually program something. Let's not get caught up on theory or hypothesis of which is a better way to code, let's prove through action.

  • mauke (unregistered)

    There are lots of problems with that header:

    #define BEGIN void main() {

    That's horribly wrong. main must return int, in C as well as in C++ (and with
    "must" I mean the C/C++ standard requires it).

    #define and &&
    #define or ||
    #define not !

    Ironically these are built-in in C++, and you may not redefine them because
    they're implemented as operators, not macros.

    #define END. }

    A dot can't be part of a macro name; this defines END as ". }", so any use of
    "END." expands to ". }.", which is more than one syntax error.

    typedef integer int;

    That's a syntax error: you can't use "int" as identifier. It should be
    typedef int integer;

    ...
    typedef pointer void*;

    Same problem, basically: typedef void *pointer;

  • Centaur (unregistered)

    Okay, they might get away with redefining begin and end in C (not ++). But then…

    std::sort(v.{(), v.}()); // Hmmm…

  • Dave (unregistered)

    It's not the only time I've seen stuff like this. Years ago (my first job actually) was with a Unix systems house who made accounting software. Their entire suite of applications was written in CBASIC - c with a header file that defined keywords as BASIC.

  • Peter Ibbotson (unregistered)

    There is a long tradition of doing this kind of thing. Steve Bourne did it with the bourne shell and the adb debugger on unix, his target language was algol. Google for bournegol for more details.

  • jasmine strong (unregistered)

    Dear Pascal programmer,

    my C programs are always smaller than your Pascal ones if you count the size of your Pascal runtime library, without which your 'smaller than Notepad' program will not run.

    Also, for your information, embedding a rich text editor widget in a window frame does not constitute 'writing an editor'.

    Hope that helps.

  • Warp (unregistered)

    "ANSI C only specifies that ... a long int is larger than an int."

    Not true. It says that a long int is at least as large as an int. It might be true that a long int is guaranteed to be larger than a short int, but I wouldn't swear that before consulting the ANSI C standard first.

  • James Curran (unregistered)

    >> isn't this anti-pattern called something like "you can write any program in fortran?"

    Actually, it's "You can write [a] FORTRAN [program] is any language."

  • Guayo (unregistered)

    In All seriousness I think using such header files just because you like a language syntax (or you just loathe curly braces) but you are forced to program in C is stupid.
    You could believe C is hardly readable but if you believe that replacing a { for "begin" (or the like) will change that, it's stupid in my book.
    I would suggest every programmer should try to decouple programming from specific language symbols syntaxes and keywords. Believing programming is just knowing a language syntax it's a too narrow view IMO.

  • Bustaz Kool (unregistered)

    StuP,
    Did you see the list of books listed as written by either himself or staff? It includes, "Cuddles the Guide Horse". (Ya can't make things like this up!)

    Fluffy,
    Z-80 => Greatest microprocessor...ever.
    8051 => Greatest microcontroller...ever.

    Real men know assembly language...

  • grunch grunch grunch (unregistered)

    Burleson looks like he should know about a company called BitFlux. They really exist: http://BitFlux.com . Drink a double bourbon and say that nine times fast: BitFlux. BotFlix. ButFlix. ButtFlux. ButtFlux. Heh heh. He said "ButtFlux". Heh heh heh. ButtFlux!

  • peter beaguely (unregistered)

    awesome, can't wait to try this in my own code.

  • Mike Prilliman (unregistered)

    That's nothing, years ago we had a programmer who copied a bunch of VB source code into a C++ project and then proceeded to write an entire function library to resolve the VB syntax. He spent weeks on the thing we came to call VB++.

    It never occurred to him that he could have easily created a COM dll from his existing VB goop and just invoked the methods he was wanting from the new C++ app - which is exactly what happened when the project went to code review...

  • Pascal Programmer (unregistered)

    Dear jasmine strong

    All programs have run time files ..this was a pure riched example, not my own editor example. For that challenge, it would take longer, and I don't have time for that challence.

    In Win32 for example you always use runtimes like shell32, kernel32, etc.

    I am talking about an application that can call riched20.dll
    If you want to write your own riched.dll then the challenge gets more complicated.

    In other words, this is a simple challenge in which you must count all "your" run time libraries as part of the file size , yes, (I have none in my program, all my runtime libraries are embedded in the EXE) As for ----"windows runtime libraries" (kernell32 etc., shellapi, etc.) those will be allowed and should be the same or similar in order for challenge to be fair.

    So you can call riched10 rather than riched20, but then I will have to laugh at you and you lose the contest, because it won't have many features (the program must have similar or better features and same or better size).

    Once again you must create it visually too. In fact you can create it non visually, and still win, but that non visual part of it will dock you points.

  • Fl8toR (unregistered)

    I would like to mention something about parenthesis and why I find them so annoying.. versus BEGIN and END:

    Although many editors have "parenthesis matching" available, the parenthesis is still hard to see. One other problem is the Keyboard... parenthesis is in an awkward position and you take your hands off the home keys when you try to access it, which takes you away from your programming.

    Yes, you can remap your keyboard, but really where on earth are you going to put that parenthesis.. on the N button? Then you can't use N ever again.. I guess you will have to hack up your keyboard with some sort of ClearKeys kit that I have seen for sale. Or buy a really expensive programmers keyboard, but those don't' even have any useful buttons in a good position (more like function key positions).

    All of this nonsense, why not just use Begin and End instead? We could try and work around the parenthesis but truth is it should have be designed better.


    (especially on a 1600 by 1200 or 1280 by 1040, monitor something any programmer should use use)

    It's not JUST that the parenthesis is a hard key to get at (pinky finger?) and that shift needs to be pressed if we haven't remapped the keyboard, it's a number of things combined together than make parenthesis an awkward thing (the hard to see factor, etc... not just one problem, but several).


    Other thing I will mention:

    Using := makes code easier to read, a lot easier... just print out some code on a piece of paper and look at it.. the = is harder to spot, := makes it extremely easier to read.

  • Warp (unregistered)

    What is easier to read and what is not is completely dependent on the individual person and his customs.
    I personally find { and } easier to spot because they look completely different from the rest of the text and because they are similar. However, 'begin' and 'end' looks just like all the other regular text in the code and are very asimilar. Unless you have a good indentation scheme (most of coders in the world don't), it's hard to find maching 'begins' and 'ends'.

  • Fleep (unregistered)

    The { }'s are easier to match up to one another. When you have tons of nested stuff, matching stuff by { }'s and indentation is way easier than awkward, non-symmetrical

    Begin
    End

    As for not being able to see them or type them easy, in the great words of Inignot, "That sounds like a personal problem."

    Nextly (my word! patent pending!) one thing I always got accustomed to doing, simply for readability, was:

    #define AND &&
    #define OR ||

    I've gotten a few chuckles over this in the past, but for me, the readability beats all. I don't see an advantage to '&&' and '||'.

    Finally, Pascal Programmer, I'm very happy you had fun writing a word processor. The rest of us have work to do.

  • jasmine strong (unregistered)

    Dear pascal programmer,

    I'm an operating system programmer. My code doesn't use any runtime library.

    You might want to acquire some clue if you think that bashing together a text editing widget and a window frame in Delphi makes you a programmer; you don't seem to have understood what kernel32 is, either.

  • Bruce Morgan (unregistered)

    In the mid-80s I worked on a project with just the same sort of stuff. The lead developer absolutely insisted on the use of a file similar to the one Sean Kleinjung posted. Apparently he was more comfortable with Pascal than C.

    Since it was a small startup and he was the only lead developer, he could enforce this. If you used regular C idioms, he'd get visibly annoyed at you. Or if he made a change to your file later , he'd also "clean it up" to use the Pascal header .

    The day he left, and I mean the day he left, I don't think the door had quite closed yet, the other three of us immediately started ripping this crap out. To this day, ripping that out was one of the most pleasing programming tasks I've ever worked on. I think we were downright giddy ...

  • Andreas H&#228;ber (unregistered)

    A nice way to clean up that mess (from #include <pascal.h>) is to let the good old C pre-processor do its magic on it and output some beautified C-code :) (note that beauty is relative to its context, so everything the C pre-processor outputs would be better to keep then this #include <pascal.h> thing :))

  • Rudy Velthuis (unregistered)

    Darren Walter wrote:

    <<
    Ok, I have no idea what is wrong with this code. Can someone break it down to me in simple terms? Monosyllabic if possible.
    >>

    ROTFLMBO!

  • BogusDude (unregistered) in reply to jasmine strong
    Anonymous:
    Dear pascal programmer,

    I'm an operating system programmer. My code doesn't use any runtime library.

    You might want to acquire some clue if you think that bashing together a text editing widget and a window frame in Delphi makes you a programmer; you don't seem to have understood what kernel32 is, either.


    Besides which, I could slap together a NON-MFC (i.e. WTL) app in visual studio in about 30 seconds that would meet Pascal Programmer's requirements.

    Personally, I belive PP is just trolling.
  • tlg (unregistered) in reply to BogusDude

    @ pascal programmer, jasmine strong (and I guess Bogusdude)

    programmer power trips - I just love 'em! [:D]  Isn't what you've just been saying to each other the "adult" version of::

    "I'm better than you"

    "No, I'M better than YOU"

    "No way, I'm the best"

    "Well I'm the REAL best"

    At which point your mum comes in and clips you round the ear [:)].  Seriously guys, just LISTEN to yourselves - if you are true uberprogrammers, you really wouldn't feel the need to justify yourselves on a message board!  Do us all a favour and stop having daydreams about your vanity-driven craziness... or don't - they're really quite funny for the rest of us [:D]

    And remember, the best programmer in the entire universe is ME! [:P]

  • kjyl nzucmqprv (unregistered)

    jqdlcumh kuza mbvw npjr yjwg xmdqpyz poslwy

Leave a comment on “#include "pascal.h"”

Log In or post as a guest

Replying to comment #25025:

« Return to Article