Should libraries have a standard API and naming convention?
-
I'm in the process of moving some code in between Javascript, .NET Core 5, .NET 7 with detours around Razor and Blazor. The code changes between them are doing my head in. Just reading a file from the browser seems to have 6 different ways, all subtly different, all similarly named. I understand that changes in underlying architecture means that one method won't necessarily translate to another, but surely there are some core things that we, as an industry, could standardise. For example: You have an object, for instance a file. Or a tensor. Or a string. - any time you get data from a source (uploaded file, network stream, from database) you call it "Get" - any time you save data to storage you call it "Save" - any time you need to append data, you call Append, and also override the + operator. The thing that's getting me is I just want to save an uploaded file. A quick check shows I can 1. Call file.SaveAs to save the file 2. Open a filestream, call file.CopyToAsync to the stream and close the stream 3. Read the file's InputStream into a buffer and call File.WriteAllBytes to save the buffer 4. Same as 2, but using CopyTo instead of CopyToAsync I'm sure there are more. I just want to save the file to disk. So I'm wondering, since I've not actually taken the time to read up on this, if this happens because 1. We're scared to break backwards compatibility so we create new methods to avoid breaking old methods, and overloading functions doesn't always work is or possible 2. There are too many ways to do a given task so we present you a bag of parts (eg streams and buffers) and let you mix and match because there's no single "default" way that's practical to provide 3. Program flow has changed sufficiently (eg async and promises) that there truly needs to be different methods to cater for this 4. We just like making up new paths for writing the same old code because they suited our headspace at the time It seems a massive waste of cycles. I think we as an industry need a big refactoring.
cheers Chris Maunder
oooohhhhhh... Hmm. Lets talk about Get. Get is a mutative verb in English. eg: You get married, You get the cold, You get to go, You get killed, You get results. You might think that last one has no effect, but trust me those results are not benign they decide everything from graduating, to informing you a baby is on its way. Getting anything is a sure sign something has changed. Also lets talk Save. When you Save a soul its not preserved on a disk somewhere. When you Save a life, it can still be lost. Saving a place doesn't mean anything is stored there. And saving a goal means preventing it from happening in the first place. So are we storing the data, or saving it from being stored? And append. Great i think we might have a winner, but a + operator? what about the humble comma? surely appending an interface to a type definition shouldn't look like:
class newType : Something + Foo + Disposable
Also Append implies order, how the hell do you append a value to a set? Add maybe, include possibly, but append? What you have discovered in your own way is the story of Babel. The simple fact of the matter is that language is defined as the common cross-section of symbols that have common interpretations across a populous. Too many symbols, Too many definitions, or too many people make it stupidly difficult to synchronise on anything. And stupidly easy for spelling mistakes like Cloneable to be quickly dispersed. We can try to say this is the language, and it will work for a number of simple ideas, i believe the English language can claim some 80+ thousand unique words. Most humans might remember 40+ thousand of those and not necessarily the entirety of their meanings. How many meanings can you name for "of"? I believe over time we will iron out the core differences. But remember human language has been around for at least 10 thousand years. Its still trying to figure out what to call a cheerio (a small Frankfurt sausage). So maybe don't hold your breath.
-
I'm in the process of moving some code in between Javascript, .NET Core 5, .NET 7 with detours around Razor and Blazor. The code changes between them are doing my head in. Just reading a file from the browser seems to have 6 different ways, all subtly different, all similarly named. I understand that changes in underlying architecture means that one method won't necessarily translate to another, but surely there are some core things that we, as an industry, could standardise. For example: You have an object, for instance a file. Or a tensor. Or a string. - any time you get data from a source (uploaded file, network stream, from database) you call it "Get" - any time you save data to storage you call it "Save" - any time you need to append data, you call Append, and also override the + operator. The thing that's getting me is I just want to save an uploaded file. A quick check shows I can 1. Call file.SaveAs to save the file 2. Open a filestream, call file.CopyToAsync to the stream and close the stream 3. Read the file's InputStream into a buffer and call File.WriteAllBytes to save the buffer 4. Same as 2, but using CopyTo instead of CopyToAsync I'm sure there are more. I just want to save the file to disk. So I'm wondering, since I've not actually taken the time to read up on this, if this happens because 1. We're scared to break backwards compatibility so we create new methods to avoid breaking old methods, and overloading functions doesn't always work is or possible 2. There are too many ways to do a given task so we present you a bag of parts (eg streams and buffers) and let you mix and match because there's no single "default" way that's practical to provide 3. Program flow has changed sufficiently (eg async and promises) that there truly needs to be different methods to cater for this 4. We just like making up new paths for writing the same old code because they suited our headspace at the time It seems a massive waste of cycles. I think we as an industry need a big refactoring.
cheers Chris Maunder
Sounds like a job for AI to suggest and fix-up names in code. Many of the code-assist tools already comply with a naming convention. And companies like Microsoft already have a naming convention that VisualStudio uses to make application development easier. Now if they can get these conventions to flow to their PowerPlatform and Azure.
-
Sounds like a job for AI to suggest and fix-up names in code. Many of the code-assist tools already comply with a naming convention. And companies like Microsoft already have a naming convention that VisualStudio uses to make application development easier. Now if they can get these conventions to flow to their PowerPlatform and Azure.
:thumbsup:
cheers Chris Maunder