Skip to main content
Tweeted twitter.com/StackSoftEng/status/1226475995332476928
added 71 characters in body
Source Link
John Wu
  • 26.9k
  • 10
  • 68
  • 92

If you're a very old programmer like me you may have written stuff like this early on:

DIM A, B, C
LET A = 2
LET B = 2
GOSUB ADD
PRINT C
END
ADD:
LET C = A + B
RETURN

(Actually, if you're an assembly programmer, you may be stuck writing stuff like this anyway, but let's not digress.)

Of course the modern approach would be more like this:

var c = Add(2,2);
Print(c); 

function Add(int a, int b)
{
    return a + b;
}

I understand the first pattern is obviously "bad;" that is not under dispute. I'm just trying to explain to another engineer the specific technical reasons why, without injecting my own opinion. A good answer will strive to be exhaustive, and stick to technical reasons, risks, and potentially cite known code smells or other authoritative sources.

If you're a very old programmer like me you may have written stuff like this early on:

DIM A, B, C
LET A = 2
LET B = 2
GOSUB ADD
PRINT C
END
ADD:
LET C = A + B
RETURN

(Actually, if you're an assembly programmer, you may be stuck writing stuff like this anyway, but let's not digress.)

Of course the modern approach would be more like this:

var c = Add(2,2);
Print(c);

I understand the first pattern is obviously "bad;" that is not under dispute. I'm just trying to explain to another engineer the specific technical reasons why, without injecting my own opinion. A good answer will strive to be exhaustive, and stick to technical reasons, risks, and potentially cite known code smells or other authoritative sources.

If you're a very old programmer like me you may have written stuff like this early on:

DIM A, B, C
LET A = 2
LET B = 2
GOSUB ADD
PRINT C
END
ADD:
LET C = A + B
RETURN

(Actually, if you're an assembly programmer, you may be stuck writing stuff like this anyway, but let's not digress.)

Of course the modern approach would be more like this:

var c = Add(2,2);
Print(c); 

function Add(int a, int b)
{
    return a + b;
}

I understand the first pattern is obviously "bad;" that is not under dispute. I'm just trying to explain to another engineer the specific technical reasons why, without injecting my own opinion. A good answer will strive to be exhaustive, and stick to technical reasons, risks, and potentially cite known code smells or other authoritative sources.

added 15 characters in body
Source Link
John Wu
  • 26.9k
  • 10
  • 68
  • 92

If you're a very old programmer like me you may have written stuff like this early on:

DIM A, B, C
LET A = 2
LET B = 2
GOSUB ADD
PRINT C
END
ADD:
LET C = A + B
RETURN

(Actually, if you're an assembly programmer, you may be stuck writing stuff like this anyway, but let's not digress.)

Of course the modern approach would be more like this:

var c = Add(2,2);
Print(c);

I understand the first pattern is obviously "bad;" that is not under dispute. I'm just trying to explain to another engineer the specific technical reasons why, without injecting my own opinion. A good answer will strive to be exhaustive, and stick to technical reasons, risks, and potentially cite known code smells or other authoritative sources.

If you're a very old programmer like me you may have written stuff like this early on:

LET A = 2
LET B = 2
GOSUB ADD
PRINT C
END
ADD:
LET C = A + B
RETURN

(Actually, if you're an assembly programmer, you may be stuck writing stuff like this anyway, but let's not digress.)

Of course the modern approach would be more like this:

var c = Add(2,2);
Print(c);

I understand the first pattern is obviously "bad;" that is not under dispute. I'm just trying to explain to another engineer the specific technical reasons why, without injecting my own opinion. A good answer will strive to be exhaustive, and stick to technical reasons, risks, and potentially cite known code smells or other authoritative sources.

If you're a very old programmer like me you may have written stuff like this early on:

DIM A, B, C
LET A = 2
LET B = 2
GOSUB ADD
PRINT C
END
ADD:
LET C = A + B
RETURN

(Actually, if you're an assembly programmer, you may be stuck writing stuff like this anyway, but let's not digress.)

Of course the modern approach would be more like this:

var c = Add(2,2);
Print(c);

I understand the first pattern is obviously "bad;" that is not under dispute. I'm just trying to explain to another engineer the specific technical reasons why, without injecting my own opinion. A good answer will strive to be exhaustive, and stick to technical reasons, risks, and potentially cite known code smells or other authoritative sources.

Source Link
John Wu
  • 26.9k
  • 10
  • 68
  • 92

Why is it better to use parameters instead of temporary global variables?

If you're a very old programmer like me you may have written stuff like this early on:

LET A = 2
LET B = 2
GOSUB ADD
PRINT C
END
ADD:
LET C = A + B
RETURN

(Actually, if you're an assembly programmer, you may be stuck writing stuff like this anyway, but let's not digress.)

Of course the modern approach would be more like this:

var c = Add(2,2);
Print(c);

I understand the first pattern is obviously "bad;" that is not under dispute. I'm just trying to explain to another engineer the specific technical reasons why, without injecting my own opinion. A good answer will strive to be exhaustive, and stick to technical reasons, risks, and potentially cite known code smells or other authoritative sources.