New answers tagged

5

You can take inspiration from .NET's TryParse series of methods. In .NET, a "TryParse" method attempts to parse the parameter it receives, and returns either true or false - true if the conversion was successful, false if it was not. The parsed number is then returned using an out parameter. You can use a similar naming scheme for your fuction. "...


0

It's fine to use terminology from the domain. Everyone who has played a game will know what a cooldown is. Write any API from the API user's view, for example interface ICooldown { int? Cooldown {get; } void OnTrigger(); }


1

Since cooldowns are associated with specific actions, it makes sense to store related state in a structure/object corresponding to that action, then you can drop the action prefix on the variables. The "cooldown duration" is typically called the "base cooldown" in games (which might be further reduced by cooldown reduction, if your game supports that concept)...


0

"Cooldown" means "not ready." It's a negative. Consider talking about readiness instead of not-readiness. actionCooldown = !IsReady actionCooldownDuration = ReadinessInterval actionCooldownCountdown = TimeTillReady or if you need to express units SecTillReady or MinutesTillReady


1

Would refactor. boolean isActionAvailable(timestamp lastTimeActionPerformed, timestamp currentTime); With the refactor, just need to keep one variable, lastTimeActionPerformed The time between actions can be static variable in the isActionAvailable() function (hardcoded) or perhaps something loaded from a resource file at runtime.


3

I'd recommend grouping these together as an object, and making IsAvailable a property/method based on the cooldown timer. Beyond that - what's the distinction between cooldown duration and cooldown timer? If cooldown duration is 'the amount of time this action always takes to cool down after use', then it sounds like part of the configuration, where-as the ...


1

I try to avoid complex directories structures to begin with. Distributing files across directories for no particular reason has no particular advantage, yet it can have a couple of disadvantages. If all files belong to the same module, I keep them in the same directory. If this leads to directories with so many files, that common file systems may get a ...


1

You shouldn't automatically use inheritance to represent variable amounts of data. It would be better to provide optional values from the base class, using Optional results.


2

Details on why you actually want to split an object into two objects would have been helpful to answer that question. In your given example, I would name the objects PersonName and Person, as that's what the objects are: One just represents the name of a person and the other one a person as a whole. And this naming implies that inheritance is not meaningful ...


5

The Name Derives from the Program/Process Created to Read it The most interesting answer I found on the subject suggest that the name of the language came as a result of the name of the program written to translate it to machine code. Quora.com user David Gish, who stated: "In the very early days of computing, programmers wrote code in binary machine ...


0

The Header (.h) file describes the interface to the code, because that's the only bit that other code gets to see. The Source (.cpp) file provides the implementation of the code that nobody else needs to know about. you include .h file which doesn't include .cpp ... Correct. As a consumer of this code, you only need the Header file so that the ...


3

You could use Lzz. It's a command line tool that takes declarations written in a C++ syntax and generates the header and source files.


2

I think it's more intuitive to name areas by function first. For example /areas/feature1 /areas/feature1/models /areas/feature1/data-access /areas/workspace /areas/workspace/data-access There are two main reasons, one it doesn't require the observer to know that the workspace feature is implemented on a filesystem. Two, it tends to remain this way longer, ...


0

I like the Flater's answer and Martin Maat's comment. But I think the answer should have more specific rules. So I’ll try to explain how I understand it. Let's divide properties and methods into categories: Action (imperative verb) - it allows us to say object do something. SetValue(value), GetValue(), Initialize(), Dispose(), Play(). Statement (third-...


12

var val = obj.GetValue(); var val = obj.PlayOnAwake; // From Unity It's not first-person, it's imperative. Simply put, it's a command. GetValue() Get the value! PlaySound() Play this sound! DeleteFile() Delete that file! These namings are used for methods, especially methods that perform a task (as opposed to returning a known value). var has = obj....


16

There are two important types of naming collisions here. You are correct in that the compiler won't have any trouble differentiating between the functions due to scope rules. Your problem is that you still have collisions inside the programmer's brain. Think about it this way: if you have 8 modules that all have a process_data() function, and you get a ...


16

There is another reason to use prefixed names even for file-local functions: they can be navigated with simple text search and text indexers without full analysis of language scoping, such as id-utils. Given that C projects often have their history going back to 90x and even earlier, it is an important reason.


38

Why prefixes in the first place? The prefix for function names is a C practice that intends to avoid naming conflicts. This is especially suitable in big projects, where different teams could easily come with do_this() and do_that() in different subcomponents of a large codebase. Since C lacks of a namespace or a package feature, the prefix is the most ...


1

Having a composite function name is acceptable, so which naming scheme you use depends on your context. There are purists who will tell you to break it up, but I will argue otherwise. There are two reasons to try to avoid such things: Purity - A function which does two things should be converted to two functions which do one thing each. Lexical size - a ...


0

What is the ultimate intent of this method? Why add these transformed ids to the DB, is it for the purpose of caching? I'll work under that assumption. It sounds like the intent of the method is really just to get the transformed response ids (either doing the transform or getting them from a cache), and so there's your method name: ...


-2

You say that the function returns something "from a transformation, not from any db action". This suggests that the function behaves more like a constructor than a getter. However, constructors also shouldn't cause side-effects (thanks for the link, @MechMK1). Factory methods, on the other hand, already presuppose some level of messiness. For example, one ...


13

As others have mentioned, using and in a function name, automatically implies that a function is doing at least two things, which usually indicates that it's doing too much or is doing something at the wrong place. Using the and clause in a function name however, in my experience, can make sense when there are some steps in a certain flow that need to be ...


2

Your function does two things: Gets a set of IDs via a transform and returns them to the caller, Writes that set of IDs to a database. Remember the single responsibility principle here: you should aim for a function to have one responsibility, not two. You have two responsibilities, so have two functions: getResponseIds - Gets a set of IDs via a transform ...


Top 50 recent answers are included