r/learnprogramming • • Mar 22 '22

Don't be that guy.

I just took over a project for a guy who left. Don't be this guy:

  • ZERO comments in your codebase.

  • One and two character variable names with no discernable pattern.

  • Comment characters used to comment out big chunks of code for no discernable reason.

  • No error checking.

  • Reliance on data files that you forgot to include or explain, going in to meaningless data frame names.

  • Making outrageous claims about how much your code improves things with zero baseline performance.

People like this think you're an idiot because you can't make their code work, and get to be all smug. We will track you down and find you. You will need references someday....oh my.

2.6k Upvotes

427 comments sorted by

View all comments

Show parent comments

15

u/Bluedragon_00 Mar 22 '22

I'm self teaching coding please don't be too harsh for asking a super 101 question. Method is a new term to me. Methodology on how you should be coding? Or is it a technical function of code I havnt learned yet?

Context: When I first started I had no idea what assigning a variable was. Im currently practicing For Loops.

22

u/[deleted] Mar 22 '22

Method basically reffers to a function that is defined inside of a class / object, you will get to it once you get to around to learning basics of OOP

13

u/Bluedragon_00 Mar 22 '22

Thank you for the reply. And for not judging too harshly.

3

u/Shit_Bananas Mar 23 '22

We've all been there lol

3

u/psioniclizard Mar 23 '22

Anyone who judges you for not knowing what a method is on a reddit for learning to program is not great. From one self taught programmer to another, nothing feels better than helping others understand!

3

u/[deleted] Mar 23 '22

No worries mate! Also try not to worry too much about people judging you on here, from my experience 99% of programmers are happy to help if they know the answer. And the few exceptions are people with a massive superiority complex. Try to just ignore those

1

u/psioniclizard Mar 23 '22

Anyone who judges you for not knowing what a method is on a reddit for learning to program is not great. From one self taught programmer to another, nothing feels better than helping others understand!

4

u/[deleted] Mar 22 '22

It's an OOP concept. A method is a function in an object, usually some sort of behavior.

5

u/Meborg Mar 22 '22

If you're practicing for loops, don't worry about methods too much, although they can be of great help to you!

What a method is, is just some code that does whatever it's supposed to, and can be called from other parts in your code. A good example of a method is the Print(input) method, which writes the "input" argument in the console. Input can be any string that you want, so when you do a Print("ladida123"), you get ladida123 printed in your console.

Anyway a good habit is that your methods do as little as possible, and have a name that describes what they do. So if you have a complicated method that does 20 things (like sort, the first thing most people do is to split up those 20 things into 20 methods, and have the complicated method run those 20 methods sequentially. And then see is you can make them simpler from there.

I hope this made any sense, if you have questions feel free to ask them! Also, what language are you programming in? :)

5

u/Bluedragon_00 Mar 22 '22 edited Mar 22 '22

I'll be honest, I'm not catching on 100%. However, I did a cursory Google search and have some things to read on when I get off work today. Thank you for going into detail.

I'm learning Python. Using Dataquest.io

Edit: I'm just about 100% lurker on this sub as I dont feel like I know enough to ask "good" questions yet. IE Trying to avoid asking stuff like "What language do I choose?" or "How long does it take to learn code?" Etc

10

u/Meborg Mar 22 '22 edited Mar 23 '22

(sorry for formatting, I'm on phone)

First of all, there are no stupid questions. The worst thing that can happen is that people find your question stupid and won't try to answer it. I wouldn't be bothered by what language to use. Everyone has a different opinion, and if you Google for the most used coding languages you get the most popular ones, which are fairly solid.

Python is perfectly fine as a language programming language, the reason I asked is so I can write code examples tailored to your needs. The structure and syntax (and conventions) in a c# application are different than in python, but at the end of the day it does the same: translate what you write into computer language that your pc can use.

Now for methods (can call them functions too), it's kinda like a codeblock that can be reused. If you write a big application that does a lot of stuff, your code monolithically goes from top to bottom. Let's say for any reason, we use a for loop to print numbers from 0 to 4 (that's what our customer pays us money for, so that's what we build).

What we would do initially is make a for loop:

for i in range(5):
    print(i)    

This bit should print 0 till 4 in our console, for a total of 10 printed numbers.

Now, I get the request to also print 0 till 6, and 0 till 2, so I add some new code:

for i in range(5):
    print(i)    

for i in range(7):
    print(i)

for i in range(3):
    print(i)

In these three bits, the only part that changes is the amount of iterations we do based on the number. As we're lazy, we want to combine this code so we can reuse it more often. One of the things we can do is to extract a function.

To do that we think of a function name that describes what we want to do. For example PrintNumbers. Then we write the function as follows

def PrintNumbers(inputName):
    for i in range(inputName):
        print(i)

PrintNumbers(5)
PrintNumbers(7)
PrintNumbers(3)

The def part defines the function. After it is defined, you can call it with the arguments.

Anyway, you can basically do that for everything you can come up with. Add numbers? Make a function that does it:

def AddTwoNumbers(num1, num2):
   return num1 + num2

result = AddTwoNumbers(1,2)

Then call it

1

u/jdon515 Mar 22 '22

Have you delved into functions yet? They're effectively python's version of a method; a piece of code that's meant to do one thing and do it well.

1

u/Dameon_ Mar 22 '22

You may know a Method better as a function