08-28-2022, 04:22 AM
(This post was last modified: 08-28-2022, 06:16 PM by JRace.
Edit Reason: I left room for improvement. (sigh)
)
Pascal was designed for clarity, so there is sometimes only one way of making your program logic work. Basic is a Swiss Army Knife; it's not always the most efficient tool for the job, but it is compact and versatile and will get the job done. C gives you a metric boatload of choices for building small, fast-running programs, even with a simple, non-optimizing compiler. Of course you don't need to use every C trick in the book, just the ones you feel comfortable with.
Trying to figure out someone else's C code can make you feel dizzy, especially if they wrote the source code for their own eyes, without considering whether other people could understand it.
Hence the old joke that Pascal is a Read-Only language, and C is a Write-Only language.
As I was learning C, experimenting with things like the ternary conditional operator (? ... :...), I discovered just how easy it is to make an unreadable, unmaintainable mess (see https://en.wikipedia.org/wiki/Internatio...de_Contest for examples, all done just for fun!). You can nest ternaries within ternaries, etc, which all feels clever & fun until you have to find deeply nested bugs.
@madscijr :
That's how I would attack it. Personally, I'd convert EVERY line of C code to a Basic comment, then start opening it up, adding spaces and blank lines, dividing it into blocks and figuring out what each block does, and what each line within each block does. Documenting everything with comments. You can use the original C as a pseudocode and create the Basic program in between lines & blocks of C code. Literal translation is possible, but as you decipher each section of code, it MAY actually be easier to rewrite from scratch in Basic.
Also, if you go back to your earlier thread "hacking into the c compiler?", I edited my reply (https://staging.qb64phoenix.com/showthre...52#pid5752) on the next day, clarifying a few things and improving that included batch file to clarify its operation.
Trying to figure out someone else's C code can make you feel dizzy, especially if they wrote the source code for their own eyes, without considering whether other people could understand it.
Hence the old joke that Pascal is a Read-Only language, and C is a Write-Only language.
As I was learning C, experimenting with things like the ternary conditional operator (? ... :...), I discovered just how easy it is to make an unreadable, unmaintainable mess (see https://en.wikipedia.org/wiki/Internatio...de_Contest for examples, all done just for fun!). You can nest ternaries within ternaries, etc, which all feels clever & fun until you have to find deeply nested bugs.
@madscijr :
Quote:Also, the code sort of works. I think if we break it down, the number of the weirder statements isn't so much.
That's how I would attack it. Personally, I'd convert EVERY line of C code to a Basic comment, then start opening it up, adding spaces and blank lines, dividing it into blocks and figuring out what each block does, and what each line within each block does. Documenting everything with comments. You can use the original C as a pseudocode and create the Basic program in between lines & blocks of C code. Literal translation is possible, but as you decipher each section of code, it MAY actually be easier to rewrite from scratch in Basic.
Also, if you go back to your earlier thread "hacking into the c compiler?", I edited my reply (https://staging.qb64phoenix.com/showthre...52#pid5752) on the next day, clarifying a few things and improving that included batch file to clarify its operation.