[Implemented] Features: lists in structure, assertions
Posted: Fri Feb 19, 2010 9:58 am
The list is short: lists and maps in structures and try-catch-finally assertion blocks.
Lists/maps in structures and the loss of encapsulation
I've begun to find more and more that some projects I'll code outright in C++ instead of PureBasic simply because the loss of encapsulation for lists makes programming a particular design a spectacular chore. Sure, I can split up the data structures into a separate file and interact with them with an additional interface on top but then I'm just emulating class-like behavior anyways, right? But to interact with a list I then have to encapsulate all of its functions --yuck! Or I could call it directly.. but then I lose encapsulation, again.
I've already written a replacement linked list library in PureBasic which I can use in structures but then I decide why bother? I can get better encapsulation out of the box using objects anyways and I don't have to rewrite data structures that already exist or implement a new interface on top of them every time I want the encapsulation.
I'm not suggesting that I'm too lazy to not just use it the way it is. It's that the resulting code makes less sense when coming back to it in the future. And where complex associated lists begin talking to each other where they exist outside of structures they should exist within, it becomes extremely difficult to read and maintain. And what about dynamically allocating lists and maps? That's impossible, unless I write my own.
So I did. I wrote my own linked list library. And the PureBasic semantics make it crazy to use and to read. But it doesn't have to be that way.
Every element must be passed as "@*This" which is in and of itself dangerous and is not well supported by PureBasic. Without references, native pointer-to-pointers and an equivalent to the arrow -> to go with it or at least a dereference operator, dealing with these pointer-to-pointer values is overly complex, error prone as a result, difficult to read, and difficult to maintain.
If I'm building some exotic data structure this might be a necessary evil. But it shouldn't be this difficult just to use lists in structures. Really, it shouldn't.
Assertions make coding infinitely simpler
See my detailed explanation of how error handling in PureBasic can be overly difficult:
http://www.purebasic.fr/english/viewtop ... =3&t=37568
Assertions make coding simpler and replace the necessity of handling and checking for error codes everywhere. Error handling and your normal code become closely intertwined. To program good rock-solid code with excellent error handling in PureBasic is a herculean effort. The resulting code is messy and it becomes hard to ensure that you have actually dealt with all possible errors. It's spaghetti code and extremely difficult to read.
One of my personal projects I've written in PureBasic was designed from the beginning to have robust error handling because it was expected to throw errors frequently and at random in any function where the state could change (as per the nature of the project).
The error handler needed to be able to handle the error appropriately, log a reverse stack trace back to the source of the error for reference including the file name and line number, and then continue from where it left off. All of this had to be accomplished with transparent support for multithreading where multiple errors could be thrown simultaneously.
The difficulty of trying to manage general coding and error handling in this project has been insane. I've rewritten this project from scratch three times now because the code just couldn't scale, handle errors elegantly, and remain as clear, maintainable code. That's asinine. I can say for certain that the next iteration certainly won't be written in PureBasic.
I've mentioned before how macro functions can alleviate a lot of the spaghetti code that is required for error handling in PureBasic. But I believe that assertions are also a necessary iteration for eliminating the inevitable error handling mess where robust error handling is essential.
This request isn't meant to bash Fred/freak in any way. It's very clear that in every new version that is always a great list of additional features. This is merely the extent of my frustration of what I've been experiencing when trying to write good code in PureBasic.
This is, for you, a very real and a very blunt synopsis of my dissatisfaction with PureBasic for certain projects where I've found it to be sorely inadequate. However, all of these projects have gone beyond what I would consider to be the bounds of PureBasic. The point I hope to convey is that PureBasic's capability in these scenarios is very weak.
Lists/maps in structures and the loss of encapsulation
I've begun to find more and more that some projects I'll code outright in C++ instead of PureBasic simply because the loss of encapsulation for lists makes programming a particular design a spectacular chore. Sure, I can split up the data structures into a separate file and interact with them with an additional interface on top but then I'm just emulating class-like behavior anyways, right? But to interact with a list I then have to encapsulate all of its functions --yuck! Or I could call it directly.. but then I lose encapsulation, again.
I've already written a replacement linked list library in PureBasic which I can use in structures but then I decide why bother? I can get better encapsulation out of the box using objects anyways and I don't have to rewrite data structures that already exist or implement a new interface on top of them every time I want the encapsulation.
I'm not suggesting that I'm too lazy to not just use it the way it is. It's that the resulting code makes less sense when coming back to it in the future. And where complex associated lists begin talking to each other where they exist outside of structures they should exist within, it becomes extremely difficult to read and maintain. And what about dynamically allocating lists and maps? That's impossible, unless I write my own.
So I did. I wrote my own linked list library. And the PureBasic semantics make it crazy to use and to read. But it doesn't have to be that way.
Every element must be passed as "@*This" which is in and of itself dangerous and is not well supported by PureBasic. Without references, native pointer-to-pointers and an equivalent to the arrow -> to go with it or at least a dereference operator, dealing with these pointer-to-pointer values is overly complex, error prone as a result, difficult to read, and difficult to maintain.
If I'm building some exotic data structure this might be a necessary evil. But it shouldn't be this difficult just to use lists in structures. Really, it shouldn't.
Assertions make coding infinitely simpler
See my detailed explanation of how error handling in PureBasic can be overly difficult:
http://www.purebasic.fr/english/viewtop ... =3&t=37568
Assertions make coding simpler and replace the necessity of handling and checking for error codes everywhere. Error handling and your normal code become closely intertwined. To program good rock-solid code with excellent error handling in PureBasic is a herculean effort. The resulting code is messy and it becomes hard to ensure that you have actually dealt with all possible errors. It's spaghetti code and extremely difficult to read.
One of my personal projects I've written in PureBasic was designed from the beginning to have robust error handling because it was expected to throw errors frequently and at random in any function where the state could change (as per the nature of the project).
The error handler needed to be able to handle the error appropriately, log a reverse stack trace back to the source of the error for reference including the file name and line number, and then continue from where it left off. All of this had to be accomplished with transparent support for multithreading where multiple errors could be thrown simultaneously.
The difficulty of trying to manage general coding and error handling in this project has been insane. I've rewritten this project from scratch three times now because the code just couldn't scale, handle errors elegantly, and remain as clear, maintainable code. That's asinine. I can say for certain that the next iteration certainly won't be written in PureBasic.
I've mentioned before how macro functions can alleviate a lot of the spaghetti code that is required for error handling in PureBasic. But I believe that assertions are also a necessary iteration for eliminating the inevitable error handling mess where robust error handling is essential.
This request isn't meant to bash Fred/freak in any way. It's very clear that in every new version that is always a great list of additional features. This is merely the extent of my frustration of what I've been experiencing when trying to write good code in PureBasic.
This is, for you, a very real and a very blunt synopsis of my dissatisfaction with PureBasic for certain projects where I've found it to be sorely inadequate. However, all of these projects have gone beyond what I would consider to be the bounds of PureBasic. The point I hope to convey is that PureBasic's capability in these scenarios is very weak.