Re: pseudo-random key generator, not bad says i
From: Tom St Denis (tom_at_securescience.net)
Date: 04/30/04
- Next message: Tom St Denis: "Re: pseudo-random key generator, not bad says i"
- Previous message: Tom St Denis: "Re: Ce-Infosys Compusec password strenghness"
- In reply to: Mark Nudelman: "Re: pseudo-random key generator, not bad says i"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: Fri, 30 Apr 2004 12:12:37 GMT
Mark Nudelman wrote:
> "Tom St Denis" <tom@securescience.net> wrote in message
> news:ITSjc.6579$huU.6564@news04.bloor.is.net.cable.rogers.com...
>
> Some generally good comments, but I have one disagreement.
>
>
>>>prng random;
>>
>>Normally it's not a good idea to define variables in the middle of code
>>blocks.
>
>
> I think it's a bad idea to declare all your variables at the top of a
> function, C-style. A variable should be declared as late as possible, just
> before its first use, so that you don't have remember the variable
> definition when you see its first use, or have to go scroll back up to the
> top of the function to see what the variable is. This style also limits the
> scope of the variable to the necessary minimum, which prevents errors where
> a variable is inadvertently used earlier than it should be used. In a way
> it's a form of data hiding -- you don't let the earlier code in the function
> see variables it doesn't need to know about. What's your objection to
> declaring variables in code?
I write functions like I write algorithms.
INPUT: BLAH
OUTPUT: BLAH
1. do this
2. do that
.
.
.
N. Output [or Return] this.
If you look at my code [more LTM than LTC] I generally do one algorithm
per C function [and usually] per .C file.
As for recalling how it was defined that's why you try not to have more
variables than you can remember but also why organizing the definition
block correctly is important. E.g.
int a, b, c;
char d,e,f;
unsigned long g,h,i;
Is harder to read than say [use monospace font here...]
int a, b, c;
char d, e, f;
unsigned long g, h, i;
In some [limited] cases yes there are going to be special short-term
variables. In LTM for instance, inside the comba multipliers. But I
make it very clear that it is a new code block. It also highlights that
the variables are only used to assist in one place... e.g.
[from one function in LTM...]
for (ix = 0; ix < pa; ix++) {
register mp_digit tmpx, *tmpy;
register mp_word *_W;
register int iy, pb;
/* alias for the the word on the left e.g. A[ix] * A[iy] */
tmpx = a->dp[ix];
/* alias for the right side */
tmpy = b->dp;
[...]
What I have against defining variables anywhere in general is that it
makes it harder to tell what variable is what [yes, I'm claiming the
exact opposite of you]. Consider a 300 line C function
int some_func(some_params....)
{
int idx_counter;
char ch;
[... 75 lines ....]
float *dct_terms = w->table[idx_counter+3];
[... 200 more lines ....]
for (int x = 0; x < 100; x++) dct_terms[x] *= sample_info[x];
Well if you jump in the file and see that last line what types are
dct_terms and sample info? Oh, well look at the start, oops no
definition, ok read through the entire function... This gets worse with
people who don't factor their code properly into a nice modular design.
If you define your variables at the top [or at least at the top of code
blocks] it's much easier to see definitions.
Tom
- Next message: Tom St Denis: "Re: pseudo-random key generator, not bad says i"
- Previous message: Tom St Denis: "Re: Ce-Infosys Compusec password strenghness"
- In reply to: Mark Nudelman: "Re: pseudo-random key generator, not bad says i"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|
|