What Are Some Of The Most Important Programming Tricks And Tips That You Should Know?


(zender fathi) #1

What Are Some Of The Most Important Programming Tricks And Tips That You Should Know?


(yane sine) #2

1.simplicity is usually better: the simple codes are always the best way to not lose your work especially when you work on large code bases, even more the simplicity is a good code quality.

2.always check your code and discuss it: some times you must check your code over and over, that’s a good idea because sometimes your co-workers have a hard time understanding your code. Maybe it’s the code that’s too complex or maybe the algorithm that you used is uncommon. making a conversation about your code is a good key for a good work.

3.have an open mind: having an open mind can make you the most successful person on earth not only in your career but in your entire life. Always accept the other’s tips and hold the anger deep down and be successful.:wink:


(danny rok) #3

Hi everyone,

these are few good tips that must be worked out.

####1-Never stop learning
Everyone thinks that when he finished a language so that’s enough, they also think that it is time to move onto another programming language for learning it.
But after a while, they’ll forget that language they learned, and they won’t learn the new language they try to learn very well because they won’t be able to divide between the two languages and they will be totally confused.
So, my advice for you is to learn something for every day even if you have already learned it, remember there is always something waits to be learned, all you need is to do some searching and to be a little bit hardworking.
####2-Use the right tools for your job
Not any tool is perfect for programming, the job of a programmer requires ideal tools, so your work’s quality will be higher, In my opinion, the first perfect tools for a programmer are books, using it can guarantee you the heightist work quality.
You can also use a notebook, so whenever you take a look at notes you don’t want to forget, all you need to do is to copy them down in your notebook so you can come back to them when you are free.
I don’t mean that you should stop using the Net it is another useful tool with many abilities, even that the things you find in the books you can find the same things on the Net, but why books are better than the Net articles? well I can think of two reasons while there is more, first, the Net articles may contain typographical errors as you know in coding there is no room for errors there is only a clean clear code, the second thing is that websites can be hacked and you can never validate any information you find on that website remember this in websites “the owner roles”, which means you will see only what the owner or editor want’s you to see, the truth or just some lies.
####3-Love what you are doing
It is obvious, to be successful in your work you must love it you must believe it is fun, always to not get frustrated from coding, ask yourself why are you doing this, then you will have
##Now these are tricks for some languages
###1. Tricks for Python
####Trick#1-The list comprehension in Python:
Let’s say that you have a list, for example,

>>>bag = [1, 2, 3, 4, 5]

when you need to double each element of the elements above, so the function of your code will be like this.

[2, 4, 6,8, 10]
Well, most programmers always will use this way.
    >>> bag = [1, 2, 3, 4, 5]
    >>> for i in range(len(bag)):
    >>> bag[i]= bag[i]* 2
I have a simple and easier way to do your trick.
>>> bag = [elem * 2 for elem in bag]

####Trick#2-Taking a string input using Python
By example, if you want to print “1 2 3 4” to get [1, 2, 3, 4] using a special code.

>>> result = map(lambda x:int(x) ,raw_input().split())
1 2 3 4
>>> result
[1, 2, 3, 4]

Remember list being returned has integers in it and don’t use more than one line of code.
###2. Tricks for C programming
####Trick#1- The return value of “scanf()”
It is the bust trick to check if your file ended.

while(~scanf(“%d”,&n)) {
/* Your solution */
}

It is very useful where inputs are terminated by EOF, that’s why you must be at online judges.
####Trick#2- The C++ Sucks.
You will be impressed when you see C++Sucks output.

#include <stdio.h>
double m[]= {7709179928849219.0, 771};
int main()
{
m[1]–?m[0]*=2,main():printf((char*)m);
}

This is the explication if you need it
####Trick#3- The “GOES TO–>” operator
Well it is not an operator, it is a combination of two separate operators i.e. — and >.
If you want to understand the “goes to” operator and how it works, go and try to understand the below code snippet.

int _tmain(){
int x = 10;
while( x –> 0 ) // x goes to 0
{
printf(“%d “, x);
}
printf(“\n”);
}

the output will be:

9 8 7 6 5 4 3 2 1 0
Press any key to continue . . .