Ideas for a Standard Library #12
Replies: 1 comment 3 replies
-
Suggestion: SQL Database Connection Support
We'd still have to choose one database for initial support, but after that it could be used as a reference implementation to support other databases. Extending it would also be a lot easier because we won't have to touch the compiler or runtime at all, only the library code. |
Beta Was this translation helpful? Give feedback.
-
Note: This was originally an issue, until I was notified that the discussion board was a better place for it.
The Otterkit Standard Library Idea
While modern COBOL has made great strides from the 1985 standard that still colors public perception, there are still a few holes where the language does not quite match up to modern standards and expectations. Therefore, there is the idea for a standard library written in 2023 Standard COBOL that is attached to the compiler. However, we need ideas, which is where this issue thread comes in.
And while every major COBOL vendor has chosen to extend and embed functionality directly into COBOL syntax, this has proven to not be ideal given the amount of incompatible dialects (sometimes with conflicting extensions). It would be much more beneficial to strictly follow the Standard COBOL syntax and provide additional methods and functions through a standard library.
COBOL is capable of conditional compilation similar to C, so any dialect could potentially benefit from this library as long as the compiler implements the required preprocessor directives and help is provided to figure out the differences to make it work.
How to format ideas.
If you have an idea for an addition to the standard library, your proposal needs three important aspects:
What is this feature? Are there any examples from other languages that implement this feature well in their standard libraries or elsewhere? What use cases does it serve? Should this feature be in the standard library(ie benefit a majority of projects/developers)?
How exactly would it work? You don't need to write a full college essay, but some clarification on expected behavior and maybe internals would be great. How would it fit in with the rest of the standard library and COBOL's language philosophy as a whole?
How hard would it be to implement? Everything takes work and time, and it's important to think about the resources it takes to implement a feature before going ahead with it. For example, while true randomness would be cool, breaking a constant server connection to a cosmic ray detector or lava lamp camera is cool but impractical, to say the least.
However, that is not usually the end. Other commenters can discuss and suggest modifications to the idea as they wish, within reason.
The First Idea
This is not only a legitimate proposal for the standard library, but an example for future proposals.
Idea: Dynamic Data Structures.
COBOL's tables work just as well as arrays in other languages, as structures of predefined length for variables of the same type. However, nearly every programming language in the modern day also has Dynamic Data Structures: structures that order data but do not have a set length. These are perfect for handling an unknown amount of elements, which is quite often. I propose to add not one but two dynamic data structures to the standard library: Vectors(Dynamic Arrays) and Linked Lists.
Both structures will be classes in the standard library that generate mutable objects. These objects will be able to store virtually any number of values of the same type. Structures will also support concatenation with tables and their own type(as in type of structure and type of value), along with stack-like properties(more on that later). These structures can also hold other structures, such as a vector holding another vector of a linked list. Assume all methods are for the instance of the respective class unless told otherwise. First, Vectors:
Head
node, and the following nodes must be traversed with anext() or prev()
method on each node.While it is technically possible for each node of a linked list to have a different type, in my proposal each vector and linked list will only hold one type of value using COBOL's generics system. Whether this includes interfaces or just regular types and classes I am sure.
These structures will also have methods that consider the structure as a whole, such as a static
equals()
that checks if two structures are of the same type and values, and acontains()
method to check if a certain value exists in a structure.These structures will also implement the
stack
interface, which will allow users to use thepush()
method to add a value to the end of the structure, and apop()
method to remove a value from the end of the structure and return the value. The linked list structure can also push and pop at the beginning.And that is finally the end. Now, any questions or comments?
Beta Was this translation helpful? Give feedback.
All reactions