What is the best way to learn programming?

  • Thread starter jd12345
  • Start date
  • Tags
    Programming
In summary: I started programming like 1-2 months ago - In most of the questions I actually try to tell the computer what I would actually do to solve the problem. I am just telling the computer what humans would do to solve that problem.This is the right approach. Try to do the same when you are writing your programs. One of the steps in writing a program is to figure out an algorithm, which is the set of steps you would do in solving the problem. The next step is to write your code in using the programming language of your choice (or the one you are learning). Then why is it tough( some questions ). I just need to tell the computer what I would do in that question but still that is tough, why
  • #1
jd12345
256
2
I started programming like 1-2 months ago - In most of the questions I actually try to tell the computer what I would actually do to solve the problem. I am just telling the computer what humans would do to solve that problem.

Is that the right practice?
 
Technology news on Phys.org
  • #2
jd12345 said:
I started programming like 1-2 months ago - In most of the questions I actually try to tell the computer what I would actually do to solve the problem. I am just telling the computer what humans would do to solve that problem.

Is that the right practice?
That's what programming is. You write the instructions that the computer performs. One of the steps in writing a program is to figure out an algorithm, which is the set of steps you would do in solving the problem. The next step is to write your code in using the programming language of your choice (or the one you are learning).
 
  • #3
Then why is it tough( some questions ). I just need to tell the computer what I would do in that question but still that is tough, why?

Also some questions like finding gcd of two numbers- humans factorise the two numbers and multiply the common factors but for the computers we use euclid's algorithm. Why the different approaches?
 
  • #4
jd12345 said:
I started programming like 1-2 months ago - In most of the questions I actually try to tell the computer what I would actually do to solve the problem. I am just telling the computer what humans would do to solve that problem.

Is that the right practice?


Yeah, that is pretty much the idea. Most computer programs are very routine logic, just done much faster than a human can do.

I would add that most humans do a rather sloppy job with logic, this reflected in the poor quality of the average computer program. So try to do better than that, if you can. The main problem is that humans tend not to consider unusual cases and get a program that crashes whenever you do anything out of the ordinary.
 
  • #5
jd12345 said:
Also some questions like finding gcd of two numbers- humans factorise the two numbers and multiply the common factors but for the computers we use euclid's algorithm. Why the different approaches?

Nobody ever prohibited humans from using Euclid algorithm nor computers from factorizing and multiplying common factors.

Method with common factors is rather difficult to code - way more operations to do (preparing list of prime factors, managing two sets of factors, finding the intersection). Euclid algorithm is much more elegant. No idea why Euclid algorithm is not taught in schools as a method; perhaps for pedagogical reasons.
 
  • #6
jd12345 said:
... I am just telling the computer what humans would do to solve that problem.
That has some pretty wide-ranging possibilities

Is that the right practice?
Easier to answer if you would provide a sample of your code.

What is your method of learning? (School, on-line courses, "how to" books, ...?)
 

1. How can I tell if my code is efficient?

One way to gauge the efficiency of your code is by analyzing its run time. If your code is taking a significant amount of time to execute, there may be ways to optimize it. You can also use tools such as profilers to identify any bottlenecks in your code.

2. Is it important to follow coding conventions?

Yes, following coding conventions is important for several reasons. It makes your code more readable and understandable for others who may need to work with it. It also helps with consistency and can make debugging easier in the long run.

3. How do I know if my code is maintainable?

Maintainable code is code that is easy to modify and update without causing any unintended side effects. To know if your code is maintainable, you can try making changes to it and see if it still works as intended. If the changes are easily implemented without breaking the code, then it can be considered maintainable.

4. Should I comment my code?

Yes, commenting your code is important for documentation purposes. It helps others understand your code and can also serve as a reminder for yourself when you come back to it after a long time. However, it is also important to strike a balance and not over-comment your code, as it can make it harder to read.

5. Is it okay to use code from other sources in my project?

It is generally acceptable to use code from other sources in your project, as long as you give proper credit and adhere to any licensing requirements. However, it is important to thoroughly understand the code you are using and make sure it fits seamlessly into your project to avoid any potential issues.

Similar threads

  • Programming and Computer Science
Replies
33
Views
2K
  • Programming and Computer Science
Replies
16
Views
1K
  • Programming and Computer Science
Replies
15
Views
1K
  • Programming and Computer Science
2
Replies
54
Views
3K
  • Programming and Computer Science
Replies
1
Views
728
  • Programming and Computer Science
Replies
5
Views
1K
  • Programming and Computer Science
Replies
8
Views
878
  • Programming and Computer Science
Replies
13
Views
1K
  • Programming and Computer Science
Replies
14
Views
2K
  • Programming and Computer Science
Replies
5
Views
849
Back
Top