New answers tagged

1

There's no real difference between a package-level global (version one for you) and a class variable. They're both implementations of a situation where the state is stored in a single place. Typically you want to avoid this for many reasons, a few including: It's difficult to track who is changing state in the case that these global values are visible to ...


0

For brevity, I think leaning on the Collections libraries would improve the readability for the First Example. Particularly, Set.retainAll(otherSet): public List<Customer> filterStepbyStep(List<Customer> customers, String searchString, List<Tag> selectedTags, List<LocationId> selectedLocations) { List<Customer> ...


0

Globals in Python are only global to the module where they belong to, not across different modules. So the scope of STATE_VAR in both of your examples is essentially the same! A class is required when you need (or expect to need) more than one instance of the abstraction formed by the module. If you are sure your program will not need this in the near ...


2

I'd suggest to a static constant string to both be able to map to i18n and keep expressiveness. Something like this is nice: { error: 'invalid_id' } And you can even scope it to module to locate the origin of the error and avoid overlapping: { error: 'auth.invalid_id' } Or, you could also add the http response code inside the object, but that's ...


0

Solution 1: Tell your team that the verb is related to the last word of the identified, and that the other words in-between give additional details, the importance of which is decreasing from right to left. So, if they want to get a path it's getPath(). If they want to say it's the path of the file, they add the detail in-between getFilePath(). if this ...


5

"File Path" is a noun phrase. You want to find a way to explain the syntax of noun phrases in english, in particular where the head noun appears (at the end in this and similar phrases), and that the the value returned should be an instance of the thing named by the head noun. Your function presumably returns a path, in particular the path of a file. If you ...


5

I cannot figure out a good way to explain why words should be in a specific order, except for "It how it's written in English" That's because it is the only reason for writing it this way. There is a naive view that there is a consensus that all programming should be done in american English. But this isn't really the case, let the developers choose ...


1

Nobody has brought this up but numbers are usually better for i18n. The client can decide what text to display. In many cases the client will have to translate the text depending on the locale, so in most cases this is easily done on the client as there are mechanisms to handle internationalization. @Bellon's answer also sends the text as well for ...


5

I would go with text. It's OK to have a string where you only use numbers. As a rule of thumb: you should not use integers for things that are not mathematical in nature. That is, if you can do addition or multiplication on the values in a sensible way, then it's a number. Otherwise it's an identifier and you should stick with text. In practice you will ...


0

If you want to send integers, send them as integers. If you have an error code “abcde” then send strings. If “12” and “0012” are different error codes then send strings. But if you the receiver wants integers, send integers.


2

Do you need to do math on it? if errorCode>9000 etc Do you need to pass it into anything that expects an integer? Do you want an early error if you accidentally type an x in the code value? If you answered no to all of these I can't see a reason why not to use strings. As for your comment about 0012 vs 12, that's a presentation issue. The backend shouldn'...


0

{ "code": 9900, "message": "Invalid ID" } Should be the most appropriate. The standard for numbers requires not to have quotes. https://www.json.org/ http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf Personally, I'd suggest to follow a pattern for code values similar to the one used by HTTP, so grouping categories of ...


0

As you commented already on your own, I think it is most important that the team carries the decision that successful linting should be required. I'm a big fan of static code analysis. I once managed to enforce a similar thing in the backend ("Treat Warnings As Errors" in C#) in an organization across several teams. At least some aspects of this were ...


4

Not exposing things is fundamentally preferable because it avoids commitment to an implementation. Once you've added something to a public interface, you cannot easily remove it ever again without possibly breaking clients. Someone, somewhere might be using it and complain if you later have to rename or remove it. You should view publishing things as a ...


0

The team I work with is very strict with linting - the helpfulness of that is something I can't understate. Unfortunately, git has no way to enforce linting. Even if it did, enforcing the correct version of the linting tool, enforcing the same configuration etc would still be a problem. So this was our solution: Our lint configurations are committed - and ...


2

Basically it boils down to "How much does your software cost to run?" Every extra bit of work your code does costs money in terms of CPU, Memory, Disk Space, Bandwidth, electricity, rack space etc etc. If its low volume, the extra cost will be tiny. But once you scale up you will be spending thousands of pounds every month. If you can knock 10% off the ...


Top 50 recent answers are included