2010-02-28
Trust in Giant Corporations
Nothing improves trust in a multi-national bank's online security quite as much as a directory listing for a home page.
2010-02-07
It's The Small Things
One reason I love VHDL is that the store operator isn't the equals sign:
Both lines of code instruct that if state_reg is equal to SHIFT, read_value should be incremented by next_value.
In C the = sign doesn't actually mean equals - that is what the == symbol means. In C, as in most programming languages, the = symbol really means "store the right-hand value into the variable." This caused me no end of confusion when I started programming - if you subtracted read_value from both sides of "read_value = next_value + read_value" wouldn't you get "0 = next_value?" In reality the line instructs the computer to add next_value to the current value of read_value, and store this sum back into read_value.
In VHDL = means equals and <= means store. Unfortunately <= also means less than or equal to. I would have preferred VHDL to use the symbol <- for store. In the first programming language I ever learned, TI-86 BASIC, there was a single-character symbol for <-. I still find the first line below to be the most intuitive of the three:
IF (SHIFT = state_reg) THENHere is some (nearly) equivalent code in C:
read_value <= next_value + read_value;
END IF;
if (SHIFT == state_reg) {
read_value = next_value + read_value;
}
Both lines of code instruct that if state_reg is equal to SHIFT, read_value should be incremented by next_value.
In C the = sign doesn't actually mean equals - that is what the == symbol means. In C, as in most programming languages, the = symbol really means "store the right-hand value into the variable." This caused me no end of confusion when I started programming - if you subtracted read_value from both sides of "read_value = next_value + read_value" wouldn't you get "0 = next_value?" In reality the line instructs the computer to add next_value to the current value of read_value, and store this sum back into read_value.
In VHDL = means equals and <= means store. Unfortunately <= also means less than or equal to. I would have preferred VHDL to use the symbol <- for store. In the first programming language I ever learned, TI-86 BASIC, there was a single-character symbol for <-. I still find the first line below to be the most intuitive of the three:
sum <- element + sumI doubt programming languages will ever change from the equals sign to something else, but I would appreciate it. Every now and then my brain seems to go into math mode, and the = symbols still cause me confusion, but the <= is close enough to <- that I don't seem to notice. Oh well, maybe I'll never master C.
sum <= element + sum
sum = element + sum
Subscribe to:
Posts (Atom)