Naming a New C API [closed] - c

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
This might not be the ideal place to ask this question, but I'm really at a dead end and don't know where else to ask (suggestions would be appreciated).
I'm trying to come up with a name for 4 new API's for my company's C Library.
These API's are being added to an existing set, so they have to match an already made pattern, which limits my choices.
What all of the API's (existing and new) do is allow the user to get/set the value string or nonstring variables used in a program.
The way mine are different is that they allow you to get the value using the name of the variable, as apposed to already existing methods.
Here is what I currently have:
VariableGetValueString
VariableSetValueString
VariableGetValue
VariableSetValue
The only problem with this, is that it does not make it clear that it uses the NAME of the variable. I cannot think of a non-cluttered sounding name that makes this clear to the customer.
Preferably, there should be nothing removed from the names, as it matches the patterns of the other API's (which do not explicitly state their retrieval methods in their names, though this one should, for extraneous reasons).
Any help is appreciated, and though I know there is no definitive answer, I will obviously accept the one that fits the best.
Sorry again if this is a poor place to ask the question, I would love suggestions of a more appropriate place if there is one.
EDIT:
Some existing API names are:
VariableGetTaskString
VariableGetTask
VariableGetGlobalString
VariableGetGlobal
Along those lines. Task and Global refer to the scope of the variable. They weren't named very well in the first place, which makes my job more difficult, but they cannot be changed because customers have grown used to them and the changes would break old programs. I didn't include these initially because of how little help they offer (in my opinion).
The parameters of each API will make it obvious to the customer what each one does, but it would be preferable for the name to do that as well. Thanks for your feedback.
EDIT 2:
Here is an example of a call into the API:
if(!VariableGetValueString(Handle handle, LPCSTR variableName, TaskID taskID, LPSRT value, DWORD bufferSizeinBytes)
{
//retrieve failed.
}
if(!VariableGetValue(Handle handle, LPCSTR variableName, TaskID taskID, PDWORD value)
{
//retrieve failed.
}
Hope thats clear enough. Feel free to keep asking for more, I'll edit this all day. Thanks for the continued support.

Here are some possibilities:
suggestion 1
UseVariableNameToGetTaskString(...);
UseVariableNameToGetTask(...);
UseVariableNameGetGlobalString(...);
UseVariableNameToGetGlobal(...);
suggestion 2
VariableGetTaskStringByVarName(...);
VariableGetTaskByVarName(...);
VariableGetGlobalStringByVarName(...);
VariableGetGlobalByVarName(...);
suggestion 3
VariableGetTaskStringByName(...);
VariableGetTaskByName(...);
VariableGetGlobalStringByName(...);
VariableGetGlobalByName(...);

How about:
NamedVariableGetValueString
NamedVariableSetValueString
NamedVariableGetValue
NamedVariableSetValue
so that the distinction NamedVariable means a variable specified by name, whereas just Variable means a variable specified by ID or whatever the old functions use.

How about:
getVariableName()
and
setVariableName(char* value)

Related

Using AI generators to ask questions to provoke thinking instead of giving answers? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I have a use case that I want to use to help independent creators talk about their interests on Twitter using their experiences.
It goes like this:
You have an interest you want to talk about Entrepreneurship
You have an experience like Pain
Is there a way for an AI (like GPT) to generate prompts that uses these two words to create a list of open-ended questions that provoke thoughts such as these:
If entrepreneurship wasn't painful, what would it look like?
What do you know about entrepreneurship that is painful that starters should know?
How can you lower the barrier to entrepreneurship so that it's a less painful opportunity for a person to take?
If so, how will it work, and what do I need to do?
I've explored Open AI's documentation on GPT-3, I'm unclear if it solves this problem of generating prompts.
Thanks!
You should provide some samples so that the GPT-3 can see the pattern and produce a sensible response from your prompt.
For example, see the following screenshot from your case. Note that the bold text is my prompt. The regular text is the response from GPT-3. In that example, I was "priming" the GPT-3 with relevant pattern: First line, the general description, then the Topics, followed by Questions. This should be enough for booting up your ideas and customizations.

What is the most efficient way to take in user input with many options in C? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I am writing a weather program that calls an API for data. One of the flags available is a preferred language, of which there are about 45 options. This leads me to the question.
What is the most efficient way to display all the language options, then allow user input, then check for valid input?
My best idea is a loop that prints all the options from a file. The user then inputs an option. Their selection is checked against the list to find a match. If there is a match then the program continues. If not, they are prompted again.
Is this the best way to go about this? I'm trying to make this program as efficient and professional looking as possible as I'm using it for my portfolio.
My best idea is a loop that prints all the options from a file. The user then inputs an option. Their selection is checked against the list to find a match. If there is a match then the program continues. If not, they are prompted again.
Is this the best way to go about this? I'm trying to make this program as efficient and professional looking as possible as I'm using it for my portfolio.
There are always multiple competing goals (single-thread performance, scalability, features, flexibility/extendibility, code readability, fault tolerance). For well designed code, its good to understand the importance of each of these goals for each piece of code (and good to understand that these importances can be different for different pieces of code in the same project). For this specific piece of code; I'd say that flexibility/extendibility (e.g. the ability to add new languages easily later) is the most important, followed by code readability (the ability to understand the code later, and find/fix bugs in it). The least important are scalability (e.g. how much performance increases when number of CPUs increases) then single-thread performance; because the code only needs to work once and is held back by the speed that a human can type anyway.
Is this the best way to go about this? I'm trying to make this program as efficient and professional looking as possible as I'm using it for my portfolio.
In terms of "human computer interaction"; the best way is to make it impossible for the user to enter invalid data (e.g. a drop down list with a well predicted default to avoid the need for a "not set yet" option). The second best way is "active status" - specifically, for every "user input event" (key press, mouse click, etc) a status field corresponding to the input field/control is updated to either indicate that the field/input is in an acceptable state, or provide the reason why it's not; where its impossible for the user to continue (e.g. because an "OK" button is disabled) until all of status fields are saying that the input is acceptable. For both of these options there is no need to validate the submitted input afterwards.
Sadly; for "command line", it's almost impossible to use the best way and almost impossible to use the 2nd best way.
In other words; you need to forget about performance/efficiency (because that's the least important); and then forget about writing software that is good/user-friendly (because it's command line).
The question then is; what is the "least bad" option? For this; I'd start by assuming that the data for each language is stored in a separate file (or directory?) where the file name is usable for display purposes; and all of the data is in a specific directory (e.g. a "project/lang" directory that contains a "project/lang/UK_English" file, a "project/lang/Spanish" file, etc). In this case you can get a list of files in the "project/lang" directory, sort them in alphabetical order, and use them to display a list of numbered options ("1) Spanish", "2) UK English", ..). Then if/when the user selects an option you can validate it (and report any errors if the user entered a bad character, a number that's too high, etc, then ask the user to retry); and load the right file for whichever language they chose (and report any errors if there's a problem with the file and ask the user to choose something else).
That way; people/translators can just create new files, and none of the code will need to be modified.
For a comparison; the fastest way is to use constant strings (e.g. puts("1) Spanish\n2) UK English\n\nEnter language choice:")); and to predict what the user will choose (e.g. based on keeping track of what they chose last time) and "pre-fetch and pre-parse" in the background (so that hopefully all the work is done for the correct choice before the user actually makes a choice), with the ability to quickly cancel the "pre-fetch and pre-parse" work if the user makes a choice that wasn't predicted. This would be extremely good for performance (likely "instant") but extremely bad (inflexible, over-complicated, too hard to maintain).

What is better: a single BAO or multiple BAOs [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
So I'm currently learning OpenGL, and while working through some of the tutorials, I've noticed that most of them create multiple buffer-array-objects (BAO) for the vertex-positions, normal-vectors and uv-coordinates. But there is also the option to just create a single BAO, where each element includes all the necessary information about a single vector. So what's the "good" or rather "recommended" way of doing things? Create multiple ones or just a single one?
From Buffer Object - OpenGL Wiki (recommended reading):
Buffer Object Usage
Buffer objects are general purpose memory storage blocks allocated by OpenGL. They are intended to be used in a great many ways. To give the implementation great flexibility in exactly what a particular buffer object's data store will be, so as to better optimize performance, the user is required to give usage hints. These provide a general description as to how exactly the user will be using the buffer object.
BO's are shared between the client and the server (in OpenGL terms). How many of them you should use, is entirely up to you. Your instincts seem to be good however. You should never optimize before you just get it working. But after you've had some experience with OpenGL, you'll probably find there are use cases, where a little early optimization can save you a lot of refactoring later on.
I can't help you much with where to draw those lines, but I would say that you should think first, about what and when you intend to render as execution progresses.

What is the point of encapsulation? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I just don't see the point of encapsulation, I see that in some cases you can modify a getter/setter to modify the behavior of something or keep track of state, but whenever I am creating a non-conventional getter/setter, I use a word like "modify," or "obtain," so what is the point of wasting hours writing repetitive methods that are practically pointless and inefficient?
I just don't get it, when I was a wee young programmer, I was told by some guy in an IRC, that not having it was the cause for a bug in my program, but I have known for years now that is not the case, I've just been doing it anyway, so what is then point?
If I need to refactor later there are ways around it weird ones but they are ways at least in languages with overloaded operators, and API's don't always have to be backwards compatible so I don't see the point.
Can anyone enlighten me to the necessity of encapsulation?
In many cases you are right - small programs doesn't need encapsulation probably.
Some MS infrastructures (C#/WPF I think in several binding scenarios) requires encapsulation (using properties) and will not work without it.
If you do more in get / set than changing the value or returning it - it will make your code nicer and more robust (do checks, or other staff in the setter for example).
No one forces you to use it anyway...

Follow original author's coding style? Even if it is horrible / lazy / makes your eyes bleed? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
When contributing to a very old, and apparently no longer maintained, open-source or public domain project, is it suggested practice to follow the original author's coding style even if it is terrible?
More importantly, are there any reasons why one would want to follow the original author's coding style rather than clean it up significantly?
Follow the original coding style. It is far, far better to be consistent, even if it's not pretty to you.
If you do decide to clean up the coding style, do it separately from any other changes. Don't clutter up source control diff's with style changes. Make one (or several) checkins where the only thing you're doing is changing code style. Do not mix in real changes with meaningless changes, it makes it impossible to locate relevant changes when reviewing source control commits.
If you know that it's unmaintained, and you're making changes to it, then I suspect that you'll become the defacto owner/maintainer going forward.
So, that said, I'd e-mail the original author/maintainer, see what they think about the formatting or style changes, and go forward with guns blazing.
If you're not submitting patches, then no. Run it through a code filter and automatically format the code in your preferred style, then hack away.
If checking into source control, you may want to leave it alone as all the style changes will make comparing to previous versions impossible.
If you do want to change the style do it with the baseline code before you make any other changes and then check it in.
Then check it out and make your coding changes. That way it will be easier to track your changes from the point you took it over.
I personally would leave the style alone unless you are making significant changes.
As stated by others, ensure that any style modifications are checked in to your version control system separately from your functional modifications.
However, my suggestion is to be bold and clean up the code as you see fit; "Leave the campsite cleaner than you found it". Cheesy, but true ;)
Just make sure that you are prepared to defend your changes ;)
Heck no! Whatever you do don't make it worse for heavens sake!
If you're adding your own code do it in your own style. This will at least make part of the codebase easy for you to maintain and understand. If you're making minor updates to existing code then you may want to follow that style.
I'm in the same boat, I have to maintain an ancient, business critical, Access 2 based system which is a complete mishmash of styles.
If it's not even maintained why are you worrying about it?
I'd write using my own preferred style, and clean up any code I had to work with. I do that regularly at work even...
Well, I'd say if you are just making a small modification within say a function, it might be clearer to go along with the bad style.
If you create new methods, classes, properties, etc., use a clear, efficient style. You might add a comment at the start of these sections, so that others can understand what's going on. You might even add a short note at the top explaining when you started on the code, and that you were using a different style, etc.
What would your answer be if the question were: Should you maintain the same shoddy workmanship when you are remodeling your home?
If you're fixing a broken wall tile in the bathroom, then it's not worth re-tiling the entire wall because they didn't use the right drywall.
When you're remodeling the kitchen, then you may correct the plumbing for that room or straighten out a bad floor. That's because it makes the rest of the job easier for you. And that's what it's all about, what kind of benefit does it give you verses the cost to you/your client.
You wouldn't rewire a lamp because it needed a new bulb.
If you're coding to a company-defined standard (or even just a team-defined standard), and the code that you're working on does not match the standard (or is so old that it doesn't match the current standard), then definitely clean up the code if you're going to be making major changes anyway. (As others have mentioned, do that to the baseline code, and check it in. Then check it out again and make the changes that you have to make to fix bugs, add features, etc.)

Resources