Propose how to name a "get/create & get" function [closed] - naming

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 6 years ago.
Improve this question
I am working on a function that returns an object from a container (e.g an Array) by value (e.g by name). If the object doesn't already exist, then a default copy of the object (default constructor) is created and returned.
That way, this function ALWAYS returns an object, regardless if the object existed prior to calling the function.
Now my question is this: how to name this function? GetOrCreateThenGet sounds stupid. Any ideas?
Edit : I feel something like this would be closer to the function's essence: GetForSure...

The best suitable name for the function would be "Provide" like if you provide goods you can ship it from a warehouse or make/buy a new one and then deliver.

Why do you need anything other than getXXX(). Any method that has and/or means that it is doing to much and is mixing concerns and seriously breaking the Single Responsibility Principle.
Should the caller actually care if the object is being created on demand if all they need from the contract is to get the object?
getOrCreate implies you will get the object or it will be created but not returned.
Again why would I care about the create part?
If I really am supposed to care it would be getOrCreateAndGet to be semantically correct, but highly unorthodox and prone to discussions with peers about methods doing to many things and mixing concerns and breaking the Single Responsiblity Principle? Just because other people name things whacky and non-sensical isn't a good excuse to do it wrong also.

GetGuaranteed seems to cover all the caller needs to know...

Related

Does cloning and writing create data race conditions in Rust? [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 1 year ago.
Improve this question
If a global variable is being cloned (as implemented within the standard library) while being written to will it create a data race?
Cloning data involves reading it. Writing to data involves, well, writing it.
We can safely access data in the following ways
Any number of threads can read data at a given moment, or
One thread can write to data at a given moment, provided no one else is reading or writing
Neither of these conditions applies (we're reading for the clone and we're writing at the same time). Therefore, yes, it's a data race.
As pointed out in the comments, Rust forbids data races. You can't so much as look at a global variable in Rust without an unsafe block, since it's never safe to do so, by Rust's rules. But if you wrap your code in unsafe and don't provide additional protection then yes, this is a data race.

What are some ways to figure out related products/questions/items anything? [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 5 years ago.
Improve this question
What are some ways including machine learning that I can use in my projects to generate things related to another. Like related apps, related websites, related products, etc.
I've been brainstorming these are strategies...
one way i can think of is show items from same category. But that would be too broad.
2nd way improves upon previous step, it's to keep track of what people click next and promote that item. Meanwhile keep bottom list randomized to let other relevant items show up and get clicked.
3rd way is to use machine learning and provide training data somehow and use that.
I want something simple but smart, as it gets better with time.
Collaborative filtering is designed for solving exactly this problem. The problem with this approach is that produces good results having a lot of data only. I mean... A LOT. And it's not a really simple thing to use. However, any machine learning technique is not simple. There are some node.js packages for CF available, but I have no idea how good are they.

Searching for simple problems naturally solved using stacks [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 5 years ago.
Improve this question
I would like to know about simple problems that can be naturally solved using stacks with the usual interface (emptyS, isEmptyS, push, pop, top).
The complexity asociated to the context of the problem should be null. I can't touch topics like parsing, compiling or search algorithms at this moment. This discards many classical examples.
The most beautiful example I found so far is checking for balanced parenthesis in strings. In very few lines, without any other background, the exercise shows the utility of the data structure:
Another good example is procesing a string where the asterisk means to pop an item from the stack and a letter means to push it into the stack. The function must return the stack after the operations described in the string are applied to an empty stack.
If you can share some others problems, I will apreciate it very much.
Thank you in advance.
Though this question is too broad, I am going to give some other applications. Some of other common applications are -
Parsing
Recursive Function
Calling Function
Expression Evaluation
Expression Conversion
Infix to Postfix
Infix to Prefix
Postfix to Infix
Prefix to Infix
Towers of Hanoi
Some details can be found here.

Why does NodeJS use JavaScript? [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 8 years ago.
Improve this question
I have to admit that I don't fully understand NodeJS. But I am thinking about using it. However what I don't understand why did the founder of NodeJS go with JavaScript? Why not with a language where for example OOP is more simple?
Ok I found some answer.
JavaScript is perfect for event loops with first class function
objects and closures. People already know how to use it this way
having used it in the browser to respond to user initiated events.
A lot of people already know JavaScript, even people who do not
claim to be programmers. It is arguably the most popular programming
language.
Using JavaScript on a web server as well as the browser reduces the
impedance mismatch between the two programming environments which can
communicate data structures via JSON that work the same on both sides
of the equation. Duplicate form validation code can be shared between
server and client, etc.
Source: What is Node.js?
But I still don't get why is it so difficult to use basic things like classes in NodeJS. Ok maybe not difficult but all the solution look like some kind of a hack job.
Edit: Why the down vote?
This question will, undoubtedly, get closed, since it's looking for opinions, but there are some objective questions in your post, so I'll answer those.
Classes are only "basic things" in OO languages that are class based, like in Java.
JavaScript is what's known as a prototypal OO language. This means that it is prototype based.
A prototype is an object that is used for generating other object. In fact, there's actually nothing special about an object that is being used as a prototype. As such, any object can be used as the prototype for a new object.
Prototypal OO can certainly be tricky if you're not used to it. However, as implemented in JS, it brings a lot of flexibility. However, with great flexibility comes great opportunities for writing bad code.

mongoose best-practice with data layer in node application [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 4 years ago.
Improve this question
looking into the nodejs server stack with nodejs/express and mongoose
What is considered a best practice solution?
(1) Creating a mongoose datamodel module then working with the model objects
(2) Creating a wrapper datalayer module that will internally use the mongoose model
Pros for (1)
I really like the OOP style classes mongoose gives me, add my own methods, my own setters and getters, I can add validation and event-handlers, and use the DataModel without redefining it in another module.
Pros for (2)
I should be able to mockup the data layer with simpler implementation (tests, etc..)
or switch a database if needed.
What do you think?
I usually start with the easiest and least complex option to start and only move to a more complex one when it's really needed. So in this case I always start with Option 1 and have yet to find an instance where I wish I had started with Option 2. If I really need to change databases, I'll do the work then instead of doing more work upfront for something I may never need.
Keep in mind that this depends on how big of a project it is and how many people are working on it. If it's a small team (or just you) extra layers of abstraction generally aren't needed. If it's a large project with a large team, I'd take a bit longer figuring out the best architecture for long term maintainability.

Resources