What's the deal with Deno? We talk with a major contributor to find out. Listen now.

Questions tagged [programming-practices]

Programming Practices are the commonly or not so commonly used practices in development of software. These can include things like Agile Development, Kanban, Coding shortcuts, etc.

Filter by
Sorted by
Tagged with
3
votes
8answers
284 views

How to scale code reviews

My boss say we should find a way to scale code reviews at our company. As it is right now, we have about 16 software developers spread across 4 different teams/squads, but soon the company will close ...
-1
votes
3answers
82 views

Difference between update a property and fire an event

It seems to me that update a property is always an 'event' and that all you can do with an event handler can be done in the property let/set routine. And, in my limited experience, I never needed to ...
0
votes
3answers
121 views

Use the type returned by a function as information

Over time I become used to use the type of the returned value of a function as a piece of additional information. For example: A function that is supposed to return or an array if the arguments are ...
-3
votes
2answers
145 views

Guards: Isn't it true the we can replace them if “if” - “else if” - “else” without any significant drawbacks? [closed]

There are a lot of examples over Internet that show why you should use guards. For example: public double getPayAmount() { if (isDead){ return deadAmount(); } if (isSeparated){ return ...
1
vote
1answer
64 views

Is it a good practice to have XML document with no-namespace elements in the middle

I have an XML looking like this: <?xml version="1.0" encoding="utf-8"?> <n0:OrderConfirmation xmlns:n0="http://company.org/interface/MVSI" xmlns:ord="...
0
votes
1answer
77 views

Efficient way to find Xor of pairs with given target X in a range 0 to K

I came across a problem: given an array (can be huge 10^8) and an integer, K, find the count of pairs in the array whose Xor equal to each value in the range 0 to K. eg: Arr = 1 2 3 K = 2 since K=...
10
votes
4answers
29k views

Returning null or a empty value/throw exception? [duplicate]

Various programming books suggest that methods should not return null values (Clean Code for example). Instead of returning null default values (0 or empty string or empty object) should be returned ...
1
vote
1answer
103 views

counting identifiers and operators as code size metric

I'm looking for a code metric for monitor and track over time the size of several projects and their components. Also, I would like to use it for: evaluate size reduction after refactoring compare ...
-2
votes
1answer
50 views

What is the term for generalised code to handle cross system functionalities

I work in a codebase which handles two countries' energy market functionalities as- payment, energy consumption, billing statements, addresses etc. For this I need to make sure that when I am writing ...
-3
votes
0answers
33 views

What tense/form should python decorator names be in?

For example, if I had a simple decorator for memoizing results, I might write it something like this: @memoize def fib(n): if n < 1: return n return fib(n-1) + fib(n-2) I was just wondering, ...
28
votes
9answers
39k views

if/else statements or exceptions [duplicate]

I don't know, that this question fit better on this site, or Stack Overflow, but because my question is connected rather to practices, that some specified problem. So, consider an object that does ...
14
votes
3answers
7k views

Exceptions in DDD

I'm learning DDD and I'm thinking about throwing exceptions in certain situations. I understand that an object can not enter to a bad state so here the exceptions are fine, but in many examples ...
-3
votes
1answer
304 views

What naming convention should I use for a JSON RPC client API designed for multiple languages?

This is the documentation with the original RPC client API specification. The naming convention in the specification is camel case. Naming conventions might differ in subtle ways for different ...
3
votes
1answer
47 views

How to test channel pipelines in Go

I use the "channel pipeline" pattern quite a lot in Go, which looks something like this: // getSomeNums spits out ints onto a channel. Temperatures, pressures, doesn't matter func ...
45
votes
6answers
8k views

Why is 2FA usually done after the correct password has been provided?

If all accounts have 2FA for a given product, is there any reason why the 2FA box couldn't be on the primary login screen? Is it bad practice to request 2FA code along with username and password on ...
-5
votes
4answers
355 views

Why are magic numbers bad practice?

Why are magic NUMBERS considered bad practice? For example: memcpy(ResourcesDir+GameDirLen, "/Resources", 11); What is wrong with the 11? Why are magical numbers so bad? Please, my question ...
33
votes
9answers
14k views

while(true) and loop-breaking - anti-pattern?

Consider the following code: public void doSomething(int input) { while(true) { TransformInSomeWay(input); if(ProcessingComplete(input)) break; DoSomethingElseTo(...
17
votes
9answers
2k views

To what extent should you program by “sketching”?

In Hackers and Painters, Paul Graham talks about how he "sketches" as he programs: For example, I was taught in college that one ought to figure out a program completely on paper before ...
14
votes
6answers
35k views

Creating a coding standards document

I work in a control systems company, where the primary work is SCADA and PLC, along with other control systems stuff. Software development is not really something the company does, apart from little ...
10
votes
6answers
754 views

Best Practice - Wrapping if around function call vs Adding early exit if guard in function

I know this can be very use-case specific, but I find myself wondering this far too often. Is there a generally preferred syntax. I'm not asking what is the best approach when in a function, I am ...
0
votes
0answers
76 views

Using for_each instead of iterators to avoid iterator invalidation

I am writing a simple custom (special purpose) container and would like to allow for iteration over each element, however, avoid using iterators due to the problem of iterator invalidation. Instead of ...
7
votes
5answers
736 views

Why are people coding “C-style C++”?

In discussions about whether to cast the result of malloc or not when coding C, one common argument is that if you cast the result then you can compile your C code with a C++ compiler. Why would one ...
2
votes
2answers
179 views

Time complexity for a small code

I'm trying to find the time complexity for the following code. N= number of elements in array D= a constant: D>1 V= a constant: V>1000 counter=1; //the maximum value of the counter is N/D. ...
1
vote
4answers
1k views

How to use Macros in Programming to make code faster, efficient and compact

Recently I was going through some of the source-codes of the best competitive programmers in the world. I found out that those people use a template while writing programs, preferably in C++. I have ...
2
votes
2answers
136 views

Better way than repeatedly passing the same parameters?

I have some methods in my code that essentially hide/show some Views, like showTitleHideBody(), showBodyHideTitle(), etc. They just change their Views' (tvTitle, tvBody) visibility. Initially those ...
1
vote
3answers
932 views

What is difference between assigning to auto-Implemented properties VS their backing fields within the class

Before I started using auto-implemented properties, I was taught that when assigning properties in the constructor (because of the potential of making a property read only), I should assign directly ...
-5
votes
1answer
41 views

Should code be refactored to be more unit testable or should a framework like PowerMock be used?

Assume there's some code that's already in production that needs some unit testing. Generally speaking, would you want to refactor this code that's already in production by adding things like adding ...
-1
votes
2answers
97 views

MVC who knows about whom?

In the Model-View-Controller pattern, I do understand the role of each component. The Model represents our application's domain model. The View presents this information and the controller ...
3
votes
1answer
104 views

What is the expected performance of While loops using `array.pop()` assignment vs other methods

Recently I was asked to refactor some code that leverages JavaScript's array.reduce() method because other developers felt the code hard to read. While doing this I decided to play around with some ...
31
votes
12answers
19k views

Is using goto ever worthwhile?

goto is almost universally discouraged. Is using this statement ever worthwhile?
63
votes
12answers
30k views

What kind of problems does MapReduce solve?

I have been reading about MapReduce for a while -- but what I can't understand is how someone would make a decision to use (or not use) MapReduce. I mean, what are the problem patterns that signal ...
11
votes
7answers
4k views

Is it bad practice to store metadata information in file names? Better solutions?

I have noticed where I work people are keen on storing information in file names, and parsing the file names. To me this doesn't seem to be especially good practice. I already see the occasional ...
0
votes
9answers
9k views

When calculating how many days between 2 dates, should you include both dates in the count, or neither, or 1?

I am trying to make an algorithm that counts the days between two dates, e.g. between 3/1/2012 and 3/2/2012. What is the correct answer, or the most popular choice? Should be the one I use? In ...
5
votes
8answers
1k views

Rule of thumb for deciding which class a method belongs to

For example, imagine a website which stores results about a certain sport or game, which has a typical "season" structure, such that there's both a Player and a Season class. To retrieve a player's ...
7
votes
3answers
4k views

Why does Facebook obfuscate the names of CSS classes?

If you look at the source code of a website such as Facebook, you'll see many classes as such: <div class="_cy6 _2s24"><div class="_4kny"><div class="uiToggle _8-a _1kj2 _4d1i _-57 _5-...
5
votes
3answers
916 views

Weighing pros and cons for using jQuery for just one widget

I have been using html select boxes or textboxes for date input. On submit, the date is validated and if invalid an error is returned. I have avoided javascript calendars thus far, but jQuery ...
-4
votes
1answer
52 views

Question about the tutorial purgatory in coding path

Dear all the programmers and overflow friend, First, I want to say thank you to stack overflow users for helping me finish 20% of my PhD project since last year (using python to draw some technical ...
7
votes
3answers
31k views

Best OOP Practice in C#: Passing the Object as Parameter VS Creating a New Instance of the Object

First of all, I would like to know if passing an object as parameter is much better than creating another object again in a class that will use it again and second what are the pros and cons of each ...
20
votes
9answers
1k views

Tips on persuading boss that code review is a good thing [closed]

Let's say one works in a hypothetical company that has several developers that rarely worked together on projects and the Boss didn't believe that code reviews are worth the time and cost. What are ...
1
vote
3answers
119 views

Good etiquette for 2 optional arguments that can't both be used

I'll demonstrate with an example of the normal distribution in Python. def norm_pdf(x, mu=0, v=1, p=1): """Returns un-normalized probability density of normal distribution at x. mu: mean v: ...
8
votes
3answers
667 views

Is it bad practice to add “false or” or “true and” to conditionals?

Is it bad practice to add false or ... or true and ... for the sake of promoting code genericness and/or ease of use? As in: SELECT * FROM table WHERE TRUE AND IsEnabled AND SomeField = some_value ...
2
votes
1answer
509 views

Using binary search in different scenarios

I have to give my one of the biggest interviews next week and I am working hard for that. I have also enrolled myself for some mock interviews for that. So, coming to the problem last day I had this ...
-4
votes
2answers
112 views

How to exploit efficiency of C? [closed]

I want to write a program that performs heavy computations and I want it to be as fast as possible, so I choose C to be the language. Nevertheless, I was told that in spite of its simplicity and high ...
78
votes
10answers
90k views

How many lines per class is too many in Java? [closed]

In your experience, what is a useful rule of thumb for how many lines of code are too many for one class in Java? To be clear, I know that number of lines is not even close to the real standard to ...
-1
votes
2answers
175 views

Explaining why a code's modifier should also be its committer [closed]

The context of this question is the early stage of introducing a VCS into an academic setting consisting of non-SW-engineers, largely unaware of modern best practices related to coding as a team. At ...
30
votes
3answers
15k views

What is the meaning of 'high cohesion'?

I am a student who recently joined a software development company as an intern. Back at the university, one of my professors used to say that we have to strive to achieve "Low coupling and high ...
0
votes
2answers
77 views

How sensible is it to build a website/app etc. using an external api?

Wanting to expand my programming horizons I recently started building a website. I have started to build up my website and it is heavily focused around an external api. The reason for using this api ...
1
vote
1answer
60 views

Using Builtin Method vs Manual Implementation

I work in a DevOps role and mainly write glue code and OS-level automation. I've rarely needed to deviate from existing language implementations or "reinvent the wheel" in the small programs I've ...
-3
votes
1answer
174 views

What are the best practices for writing a long, multi-step process? [closed]

When writing a long process, i.e. one filled with many steps of business logic, what are the best practices for organising it? There are a few different options here that I can see: Just write a long ...
-4
votes
3answers
102 views

What can an assertion test that running the actual code cannot?

I'm currently learning Jest, Enzyme, Detox and testing in general, but I'm still trying to grasp the benefit of testing. From what I understand, testing is about creating hypothetical situations. Let'...

1
2 3 4 5
30