3 ms·
> A rewrite would introduce new bugs, even if they aren't memory issues. OTOH, a rewrite could be useful in splitting up the problem-space as well as reducing
by OneWingedShark 6y ago
> A rewrite would introduce new bugs, even if they aren't memory issues.
OTOH, a rewrite could be useful in splitting up the problem-space as well as reducing errors. This is where Ada excels, and one nice way of splitting the problem-space could be in providing types (perhaps with provable properties via SPARK) that properly decompose the problem-space.
-- Small, quick/dirty "back-of-napkin" design.
Package Uniform_Resource_Locator is
Type Protocol is (HTTP, HTTPS, FTP, SFTP, ETC );
Type URL is private;
Function Get_Protocol(Object : URL) return Protocol;
-- other operations.
Function Parse(Text : String) return URL; -- Text to URL.
Function "+"(Object : URL) return String; -- URL to Text.
Private
Type URL is record
--...
end record;
End Uniform_Resource_Locator;
> The rewrite could end up buggier than the original.
Given the properties of a language like Ada, you could decompose the problem-space into types (like above) and leverage the language properties to ensure the correctness of the program. For example, Ada mandates full-coverage on cases can so when you say `case Get_Protocol(The_URL) is ...` you have to provide for every value in the enumeration (Protocol here), and the compiler enforces this. So, every place you have a case-statement operating on a Protocol value, absent the `others` option, the compiler will error-out and point you to the location you're missing a value.
...meaning that you can update the Protocol enumeration and have the compiler complain at every location you need to fix/implement the new protocol.
- jayp1418 6y agoThis might interest you https://github.com/1ma/CurlAda https://github.com/1ma/CurlAda