Question:
How does a programmer analize a code?
fahad
2010-09-27 14:45:14 UTC
How does a programmer see a code if it works? I mean how does professional programmers point out the mistakes at first instance..Please refer me some tricks
Eight answers:
?
2010-09-27 15:16:19 UTC
Most professional programmers, once they've cut some code, let the compiler point out potential problems, such as pointer misuse or uninitialized variables. Turning a compiler's error message option to "Warning" or whatever is the strictest is one "trick".



After that, they try to run it with test data and see what happens. When a bug shows up that's not obvious, they may put in test output statements to localize the problem. That's another "trick."



Echoing input before using it is a third.



Implementing and debugging in phases rather than all at once is a fourth.



Hope that helps.
SomeGuy
2010-09-27 15:02:35 UTC
It just takes practice of doing code yourself. For instance when you start off programming there are many errors you are going to make such as (put = instead of == [in C++] and so on and so fourth)

So when you read other people's code you are most likely to spot out that problem in the code rather than a problem that didn't occur with you. It's just how we humans are. If our eye catches something we recognize we tend to focus on that. So the answer is just to keep programming and it'll become easier.



Some tricks you probably can use are these (but it still might be harder to spot the problem)

1.Most times people make a simple mistake but it affects the way the program runs.

ex : num1 + num2 = result ..... It should be the other way around result = num1 + num2;

if a coder put something like that it would leave an error.

Another example could be in an if statement (C++)

if (num1 = num2) ... the right answer should be if (num1 == num2) [Note: 2 = signs]

If you put something like that it would cause an error to your code execution.



2. A variable name could be wrong or put in the wrong spot.



3. Sometimes a command can be written incorrectly (most common with beginners).



4. A code that has an infinite loop

Ex: for (int i = 1 ; i >= 0; i++)



5. One piece of code could be missing.



6. There's lots more. I can't really explain how I analize it, It's just when there's an error it catches my eye because most of the errors I see I've made that mistake before and therefore I'm used to seeing that mistake.



Hope this helped you a bit :D
green meklar
2010-09-27 18:23:18 UTC
There are no real 'tricks'. The ability to analyze code basically comes along with the ability to write it. Both stem from the same programming concepts. Of course, if all else fails, you can always run the code and see what happens. Real programmers do this all the time in order to isolate bugs and get rid of them.
Nik
2010-09-27 15:26:13 UTC
This one is a simple one my only real programming languages are PHP and VB but the key is experience. Just by learning how a language does something as in PHP database connection you start to learn it of by heart which then gives you the knowledge to point out mistakes in other peoples code. After doing it for 3 years I can look at PHP code and instantly point out errors or flaws within it.



When people ask questions how to do xyz in VB I do not have to open VB 2010 to verify my own code.



Having said all this people who study it extensively still make mistakes from time to time.
MasculinePit103
2010-09-27 15:02:33 UTC
It all has to do with knowing the language and generally how to program.

If a programmer notices the use of an = rather than a == or lack of a semicolon, they'll tell you.



I have checklists with problems that I personally experience a lot.

My personal mySQL checklist, for example, is:

-try with/without semicolon

-try with single quotes/dual quotes/backticks

-case sensitive?

-typos in the column?

-a column name a reserved word?

-any other reserved word occurrences?

-escape all characters properly

-WHERE goes after SET in UPDATE (That's a problem I personally have lots of trouble with)

-Multiple WHERE clauses use AND, not &. (Another problem I personally have.)



These are just some examples; the main thing to look out for is syntax errors. Keep a mental checklist, and make sure you're good with a language's syntax, and you'll be able to easily check errors.
question asker
2010-09-27 16:35:09 UTC
Print variables to console and/or log file as the program is running. It is also very helpful to use an IDE that highlights syntax errors in the code.
?
2016-11-16 18:28:13 UTC
im guessing you want the c software language codes to make classes ,you could seek the internet for a particular utility alongside with keyloggers,(do you realize them?)yet thats like cheating maximum suitable? i will advise to you to bypass and study the thank you to place in writing algoritms first then study C or C++ then it would be exciting to make softwares,there are a number of books that coach you suggestion on the thank you to place in writing in codes
Big Bean
2010-09-27 14:55:21 UTC
I've been programming for a while and there aren't any 'tricks' that I'm aware of. It just comes with experience.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...