Topics

Finding variables in source code

Jack Purdum
 

I think we all run into situations where we need to find the definition of a variable or object in a large set of files. The UNIX tool Grep is perfect for doing that. The Grep version I use is not longer available, but I just downloaded and tried this version and it seems to work well:



If you want to change the data type of a variable, use Grep and type in the variable name, supply a search path, and BINGO it finds all occurrences of that string in the directory/subdirectories seach.

Jack, W8TEE



On Sunday, July 15, 2018, 11:06:15 AM EDT, Lee <mr.olson@...> wrote:


Thanks Mike,  I did not know about General coverage mode.  It seems to step buy .1MHZ  which is what I was trying to do.  Thanks to the others for the WWV ideas but my reference to WWV was an example. 

My changes work as I wanted but I still would like to figure out how to make it display correctly.  I cannot find where to change the data type to unsigned long.
--
Lee - N9LO  "I Void Warranties"

 

AA9GG
 

I remember GREP from the old DOS days.  Most editors for programming have a search feature. One could also load the code into a text editor and use its search function.  

Virus-free. www.avast.com

On Sun, Jul 15, 2018 at 11:22 AM, Jack Purdum via Groups.Io <jjpurdum@...> wrote:
I think we all run into situations where we need to find the definition of a variable or object in a large set of files. The UNIX tool Grep is perfect for doing that. The Grep version I use is not longer available, but I just downloaded and tried this version and it seems to work well:



If you want to change the data type of a variable, use Grep and type in the variable name, supply a search path, and BINGO it finds all occurrences of that string in the directory/subdirectories seach.

Jack, W8TEE



On Sunday, July 15, 2018, 11:06:15 AM EDT, Lee <mr.olson@...> wrote:


Thanks Mike,  I did not know about General coverage mode.  It seems to step buy .1MHZ  which is what I was trying to do.  Thanks to the others for the WWV ideas but my reference to WWV was an example. 

My changes work as I wanted but I still would like to figure out how to make it display correctly.  I cannot find where to change the data type to unsigned long.
--
Lee - N9LO  "I Void Warranties"

 




--
Paul Mateer, AA9GG
Elan Engineering Corp.
www.elanengr.com
NAQCC 3123, SKCC 4628

Arv Evans
 

The Arduino IDE, and most other IDEs include "find" and "find next"  in the edit commands.
This is very similar to the now ancient UNIX grep, fgrep, etc that eventually made its way into
several DOS editors.  Linux has continued the grep legacy in original and several new forms.
Not sure but I would think that Apple's OSX would also include the function as it was there in
original BSD UNIX.  It is also present in the shell programming tool for my Linux based
Android cell phone.

Us real old timers might use use SED (stream editor)to find and change specific words in
one pass.  This is handy for changing all occurrences of a word in the whole document.

Arv K7HKL
_._


On Mon, Jul 16, 2018 at 3:07 PM AA9GG <paul.aa9gg@...> wrote:
I remember GREP from the old DOS days.  Most editors for programming have a search feature. One could also load the code into a text editor and use its search function.  

Virus-free. www.avast.com

On Sun, Jul 15, 2018 at 11:22 AM, Jack Purdum via Groups.Io <jjpurdum@...> wrote:
I think we all run into situations where we need to find the definition of a variable or object in a large set of files. The UNIX tool Grep is perfect for doing that. The Grep version I use is not longer available, but I just downloaded and tried this version and it seems to work well:



If you want to change the data type of a variable, use Grep and type in the variable name, supply a search path, and BINGO it finds all occurrences of that string in the directory/subdirectories seach.

Jack, W8TEE



On Sunday, July 15, 2018, 11:06:15 AM EDT, Lee <mr.olson@...> wrote:


Thanks Mike,  I did not know about General coverage mode.  It seems to step buy .1MHZ  which is what I was trying to do.  Thanks to the others for the WWV ideas but my reference to WWV was an example. 

My changes work as I wanted but I still would like to figure out how to make it display correctly.  I cannot find where to change the data type to unsigned long.
--
Lee - N9LO  "I Void Warranties"

 




--
Paul Mateer, AA9GG
Elan Engineering Corp.
www.elanengr.com
NAQCC 3123, SKCC 4628

Clark Martin
 

I use TextWrangler on my Macs.  It has a very capable search function including grep capability.  I use it for most of my code development.


Clark Martin
KK6ISP

On Jul 16, 2018, at 2:21 PM, Arv Evans <arvid.evans@...> wrote:

The Arduino IDE, and most other IDEs include "find" and "find next"  in the edit commands.
This is very similar to the now ancient UNIX grep, fgrep, etc that eventually made its way into 
several DOS editors.  Linux has continued the grep legacy in original and several new forms.
Not sure but I would think that Apple's OSX would also include the function as it was there in 
original BSD UNIX.  It is also present in the shell programming tool for my Linux based 
Android cell phone.

Clark Martin
 

I should add, it has a multi-file search capability which is excellent for searching source code for definitions, declarations, etc.

Clark Martin
KK6ISP

On Jul 16, 2018, at 2:47 PM, Clark Martin <kk6isp@...> wrote:

I use TextWrangler on my Macs. It has a very capable search function including grep capability. I use it for most of my code development.

W2CTX
 

IDE "find" is really handy but it only searches the currently opened file.  The old

"grep" command can search many files.


ron

On July 16, 2018 at 5:21 PM Arv Evans <arvid.evans@...> wrote:

The Arduino IDE, and most other IDEs include "find" and "find next"  in the edit commands.
This is very similar to the now ancient UNIX grep, fgrep, etc that eventually made its way into
several DOS editors.  Linux has continued the grep legacy in original and several new forms.
Not sure but I would think that Apple's OSX would also include the function as it was there in
original BSD UNIX.  It is also present in the shell programming tool for my Linux based
Android cell phone.

Us real old timers might use use SED (stream editor)to find and change specific words in
one pass.  This is handy for changing all occurrences of a word in the whole document.

Arv K7HKL
_._

On Mon, Jul 16, 2018 at 3:07 PM AA9GG < paul.aa9gg@...> wrote:
I remember GREP from the old DOS days.  Most editors for programming have a search feature. One could also load the code into a text editor and use its search function.  


Virus-free. www.avast.com

On Sun, Jul 15, 2018 at 11:22 AM, Jack Purdum via Groups.Io <jjpurdum@...> wrote:
 
I think we all run into situations where we need to find the definition of a variable or object in a large set of files. The UNIX tool Grep is perfect for doing that. The Grep version I use is not longer available, but I just downloaded and tried this version and it seems to work well:



If you want to change the data type of a variable, use Grep and type in the variable name, supply a search path, and BINGO it finds all occurrences of that string in the directory/subdirectories seach.

Jack, W8TEE



On Sunday, July 15, 2018, 11:06:15 AM EDT, Lee < mr.olson@...> wrote:


Thanks Mike,  I did not know about General coverage mode.  It seems to step buy .1MHZ  which is what I was trying to do.  Thanks to the others for the WWV ideas but my reference to WWV was an example. 

My changes work as I wanted but I still would like to figure out how to make it display correctly.  I cannot find where to change the data type to unsigned long.
--
Lee - N9LO  "I Void Warranties"

 

 

 




--
Paul Mateer, AA9GG
Elan Engineering Corp.
www.elanengr.com
NAQCC 3123, SKCC 4628

 

 

Jack Purdum
 

True, Ron, and that's were Grep shines over most editors, since they are usually limited to the current file. Grep not only searches all of the files in the current directory, it also search all of the subfolders of the current directory. Often that "deep search" is exactly what's needed.

Jack, W8TEE

On Monday, July 16, 2018, 6:52:27 PM EDT, W2CTX <w2ctx@...> wrote:


IDE "find" is really handy but it only searches the currently opened file.  The old

"grep" command can search many files.


ron

On July 16, 2018 at 5:21 PM Arv Evans <arvid.evans@...> wrote:

The Arduino IDE, and most other IDEs include "find" and "find next"  in the edit commands.
This is very similar to the now ancient UNIX grep, fgrep, etc that eventually made its way into
several DOS editors.  Linux has continued the grep legacy in original and several new forms.
Not sure but I would think that Apple's OSX would also include the function as it was there in
original BSD UNIX.  It is also present in the shell programming tool for my Linux based
Android cell phone.

Us real old timers might use use SED (stream editor)to find and change specific words in
one pass.  This is handy for changing all occurrences of a word in the whole document.

Arv K7HKL
_._

On Mon, Jul 16, 2018 at 3:07 PM AA9GG < paul.aa9gg@...> wrote:
I remember GREP from the old DOS days.  Most editors for programming have a search feature. One could also load the code into a text editor and use its search function.  


Virus-free. www.avast.com

On Sun, Jul 15, 2018 at 11:22 AM, Jack Purdum via Groups.Io <jjpurdum@...> wrote:
 
I think we all run into situations where we need to find the definition of a variable or object in a large set of files. The UNIX tool Grep is perfect for doing that. The Grep version I use is not longer available, but I just downloaded and tried this version and it seems to work well:



If you want to change the data type of a variable, use Grep and type in the variable name, supply a search path, and BINGO it finds all occurrences of that string in the directory/subdirectories seach.

Jack, W8TEE



On Sunday, July 15, 2018, 11:06:15 AM EDT, Lee < mr.olson@...> wrote:


Thanks Mike,  I did not know about General coverage mode.  It seems to step buy .1MHZ  which is what I was trying to do.  Thanks to the others for the WWV ideas but my reference to WWV was an example. 

My changes work as I wanted but I still would like to figure out how to make it display correctly.  I cannot find where to change the data type to unsigned long.
--
Lee - N9LO  "I Void Warranties"

 

 

 




--
Paul Mateer, AA9GG
Elan Engineering Corp.
www.elanengr.com
NAQCC 3123, SKCC 4628

 

 

Jon Titus, KZ1G <tituskz1g@...>
 

The problem with how to locate variables also involves how programmers label them.  Too many books, teachers, and hobbyists use nonsense variables such as i, j, index, ptr, and so on as variable names.  Use variable names that indicate how you use them--Keyboard_Input, XMIT_Switch_State--and you save yourself and others endless searches and wasted time.
--
Jon Titus, KZ1G
Herriman, UT USA

Jack Purdum
 

It depends. I use i, j, and index quite often in my code and find nothing wrong with it because those variables are almost always used for the same purpose and are rarely the source of program bugs. Everyone has their own coding style...unless you work as a programmer where style is dictated. Personally, I never use an underscore in a variable name for two reasons: 1) double-underscores were typically used as system variables and I still think that when I see them (it's a personal problem), and 2) while I can probably type 70wpm, the underscore key slows me down because I rarely use it. Some coding conventions I've found useful:

    1. Start variable names with a lowercase letter, and only cap the first letter of sub-words: keyboardInput, xmitSwitchState, ptrSisters.
    2. Start function names with an uppercase letter. That way you can tell in a glance whether it's a variable or a function. That's especially useful when you use pointer to         functions.
    3. Variables are like nouns in a sentence. Typically they reflect something of interest in the program and the name should convey that.
    4. Make the name long enough to convey that interest, but short enough you don't find it burdensome to type it over and over.
    5. Function are like verbs in a sentence. Typically they reflect an action taken and the function name should reflect the action, but not the means of the action. That is,         SortList() is a better name than BubbleSortList() because the former says what's to be done, while the latter says what's to be done and here's how I'm going to do it.
        a. Functions are black boxes with no windows. It's nobody else's business what goes on inside. What happens in functions stays in functions. Do you really want to force             users to recode their programs because you stopped using a Bubble Sort and switched to a Shell Sort? Hint: NO.
    6. Make functions cohesive. It you cannot say what a function does in two sentences, it's probably trying to do too many things. Break it into two smaller, and probably more         reusable, functions. Beginning students too often try to write Swiss Army Knife functions; they do a lot, but nothing well. Rarely is a function with a long parameter list a         cohesive function. Passing in flag variables is a dead giveaway that you're trying to make the function do too many things.
    7. Learn how to read and use complex data definitions. For example, what does this definition define:

                double (*(*pf)())[3][4];

        It's easier than you think to figure this out using the Right-Left Rule. (See:http://jdurrett.ba.ttu.edu/3345/handouts/RL-rule.html) Because C allows you to "create" new data types, it's an extremely robust and power language.

Writing C code is a personal thing and everyone is free to write it anyway they want as long as the compiler can parse it. However, when you know someone else has to read it, clarity starts to gain importance and style plays a part, too.

Jack, W8TEE

On Monday, July 16, 2018, 11:13:12 PM EDT, Jon Titus, KZ1G <tituskz1g@...> wrote:


The problem with how to locate variables also involves how programmers label them.  Too many books, teachers, and hobbyists use nonsense variables such as i, j, index, ptr, and so on as variable names.  Use variable names that indicate how you use them--Keyboard_Input, XMIT_Switch_State--and you save yourself and others endless searches and wasted time.
--
Jon Titus, KZ1G
Herriman, UT USA

Jon Titus, KZ1G <tituskz1g@...>
 

Good advice, Jack.  Thanks for sharing it.
Cheers.
--
Jon Titus, KZ1G
Herriman, UT USA