Questions tagged [programming-logic]

According to Wikipedia, Logic (from the Ancient Greek: λογική, logike)[1] has two meanings: first, it describes the use of valid reasoning in some activity; second, it names the normative study of reasoning or a branch thereof.[2][3] In the latter sense, it features most prominently in the subjects of philosophy, mathematics, and computer science.

According to Wikipedia, Logic (from the Ancient Greek: λογική, logike)1 has two meanings: first, it describes the use of valid reasoning in some activity; second, it names the normative study of reasoning or a branch thereof.[2][3] In the latter sense, it features most prominently in the subjects of philosophy, mathematics, and computer science.

59 questions
66
votes
16 answers

How to avoid logical mistakes in code, when TDD didn't help?

I was recently writing a small piece of code which would indicate in a human-friendly way how old an event is. For instance, it could indicate that the event happened “Three weeks ago” or “A month ago” or “Yesterday.” The requirements were…
Arseni Mourzenko
  • 134,780
  • 31
  • 343
  • 513
55
votes
11 answers

How would you refactor nested IF Statements?

I was cruising around the programming blogosphere when I happened upon this post about GOTO's: http://giuliozambon.blogspot.com/2010/12/programmers-tabu.html Here the writer talks about how "one must come to the conclusion that there are situations…
saunderl
  • 655
  • 1
  • 6
  • 7
54
votes
6 answers

Business logic: Database vs code

I'm a student of systems engineering, and all my teachers and friends (that actually work in the area) say that it is better to have as much logic as possible implemented in the database (queries, views, triggers, T-SQL, etc.). I think that it's…
Larizza Tueros
  • 714
  • 1
  • 5
  • 12
41
votes
15 answers

Arguments for or against using Try/Catch as logical operators

I just discovered some lovely code in our companies app that uses Try-Catch blocks as logical operators. Meaning, "do some code, if that throws this error, do this code, but if that throws this error do this 3rd thing instead". It uses "Finally" as…
James P. Wright
  • 2,135
  • 4
  • 18
  • 25
36
votes
14 answers

How to define "or" logically

Recently, I came across a problem that required me to define the logical "OR" operator programmatically, but without using the operator itself. What I came up with is this: OR(arg1, arg2) if arg1 = True and arg2 = True return True else if…
logicNoob
  • 511
  • 4
  • 6
28
votes
7 answers

What do you do to improve your logical programming skills?

Do you think that only the programming pratice will help you to improve your logical programming skill or do you train your brain with puzzle games, trying imagine how universe works, playing instruments and so on? Devoting more time with…
killown
  • 1,466
  • 3
  • 15
  • 18
21
votes
9 answers

How to turn truth table into smallest possible if / else block

How can I take a truth table and turn it into a compacted if block? For instance, let's say I have this truth table where A and B are conditions and x, y and z are possible actions: A B | x y z ------------- 0 0 | 0 0 1 0 1 | 0 0 1 1 0 | 0 1 0 1 1 |…
16
votes
5 answers

When is it appropriate to use a bitwise operator in a conditional expression?

First, some background: I am an IT teacher-in-training and I'm trying to introduce the boolean operators of java to my 10th grade class. My teacher-mentor looked over a worksheet I prepared and commented that I could let them use just a single & or…
Deerasha
  • 165
  • 1
  • 1
  • 8
11
votes
2 answers

Handling subscriptions, balances and pricing plan changes

Preamble My aim is to create reusable code for multiple projects (and also publish it on github) to manage subscriptions. I know about stripe and recurring billing providers, but that's not what this module is aiming for. It should just be a…
pdu
  • 579
  • 1
  • 6
  • 21
10
votes
3 answers

What is the best practice around De Morgan's Law

We all know De Morgan's Laws !(a && b) === (!a || !b) !(a || b) === (!a && !b) Is there a community consensus around which one of these representations is easier to reason about (and therefore) produces more maintainable code? If there is not, what…
Abraham P
  • 269
  • 2
  • 8
10
votes
7 answers

Programming knowledge vs. programming logic

Is there any difference between the two topics? I have seen companies asking for Good Programming knowledge some Good Programming logic. I have seen this in Job profiles for a developer – for e.g. "good Programming logic", "strong Programming…
Shirish11
  • 1,469
  • 10
  • 22
8
votes
3 answers

Ordering if conditions for efficiency and clean code

This is purely a design question and the example is simple to illustrate what I am asking and there are too many permutations of more complex code to provide examples that would cover the topic. I am not referring specifically to this example, just…
user208372
7
votes
1 answer

Is the separation of program logic and presentation layer going too far?

In a Drupal programming guide, I noticed this sentence: The theme hook receives the total number of votes and the number of votes for just that item, but the template wants to display a percentage. That kind of work shouldn't be done in a template;…
Timwi
  • 4,411
  • 29
  • 37
6
votes
2 answers

What is the logic in the order of operator precedence?

Absolutely academic context question- I found countless articles listing the order of operator precedence in all languages, but what is the logical reasoning behind that specific order? For clarity of answers, let's talk about the C/C++/C#…
Benson
  • 79
  • 3
5
votes
1 answer

Good way to program an orchestration / processflow

I'm programming a process in which clients will be separated in 3 different groups, and for every group a different action will be performed. My question concerns the process of deciding which client will be in which group. As input I received a…
Michel
  • 971
  • 1
  • 7
  • 17
1
2 3 4