4 ms·
I use Pascal as better C
by benibela 7y ago
I use Pascal as better C
- Koshkin 7y agoPascal is not better, it's just more verbose.
- benibela 7y agoPascal is better, because it has an actual string type that can store \0 characters, and a boolean type, and reference-counted dynamic arrays, and set types, and ranges in case statements (that makes it less verbose!), and a for loop that can go to MAXINT without overflow
- pjmlp 7y agoJust a couple of ways how it is better, using Turbo Pascal 7 for MS-DOS, released in 1992. - Units (modules) for separate compilation with strong type checking and not needing useless prefixes - A proper string type - Proper arrays with bounds checking, it has functions to retrieve upper and lower bounds - Allows the definition of numeric ranges - Enumerations are their own type, can be used as array indexes or data sets - Support for sets - Thanks to reference parameters there is less need to deal with pointers that might be invalid - Already allows for a simplified way of doing Type Driven Development - Supports type safe function pointers - Supports single inheritance OOP with minimal RAII support for heap allocated objects - Comes with a quite powerful OOP framework for TUI applications, Turbo Vision - While it doesn't prevent use-after-free, it allows for memory regions that can be deallocated on one go - Can map arrays to memory regions with bounds checking - Besides inline assembly without UNIX's clusmy syntax, allows to use registers as variables - If one really wants do do unsafe C style coding there are compiler pragmas to allow it and yes even pointer arithmetic and unsafe casts. This in 1992, if I take a recent version of Delphi, FreePascal or Oxygene, there are even more bullet points.
- Koshkin 7y agoUnfair comparison: Turbo Pascal 7 is more like C++20.
- pjmlp 7y agoNot really, hence why I mentioned 1992. C has had plenty of time to catch up, but apparently it wasn't something that WG14 cared about. And it is not like many aren't actually coding in GCC C, Clang C, TI C, xlc C, aC C and so on. Which even with those C extensions fail on the security story.
- strbean 7y agoAt university, my classes in C required using C89. The rationale given by the professor was that he wanted us prepared for industry, and if you learn to stick to C89 you will be able to write C for any job out there. I argued that C99 block scoped variables free up stack space (pretty silly argument but true), he wasn't buying it. I think this kind of thinking is very common across the C community.
- sitkack 7y agoAnd to be clear, this kind of thinking hampers progress in the name of genericity. The ironic thing, is when someone makes that argument, they are admitting that the education they are giving creates students around the mean. When I teach someone, I try to give them a mental framework that others don't have and some unique skills that will differentiate them. Learning C89 gives someone the "most chances" of getting a random job who hasn't upgraded to better technology (◔_◔). Where if I show someone how to use a constraint solver to optimize something, or how to run a quick Monte Carlo simulation to test a hypothesis, those folks will have a huge advantage over the C89 slinging autobot. The only reason to learn "popular tech" is to hide within a flock of nameless cogs.
- WalterBright 7y agoAfter I discovered C, I never wrote another line of Pascal :-)