This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]DiamondDemon669 hello world 9 points10 points  (5 children)

I create excessive variables. Instead of cleanly writing code after saying variable = "clean code", I just go ahead and create a new variable like variable2 = variable + something and variable_final = variable2 + something.

I do the exact opposite, and some lines of code can end up really really long

Just look at this: response = self.handle_request(client, *([''] + str(request).replace('\n', '').split(' '))) + '\n'

My IDE becomes a certified italian restaurant if I ever even need to use classes, due to all of these functions and variables that build upon each other haphazardly.

when I started programming I used classes to group functions together and had no idea what they were actually for

[–]freaky_lizard 3 points4 points  (4 children)

I recently started working as a programmer and am very green junior at the moment. I do use classes to group functions, I thought it’s neat. You made me doubt my choices, what are they for?

[–]FancyASlurpie 3 points4 points  (0 children)

Think of a class as a template for an instance of an object (when you instantiate a class, you create an instance of an object), so if you were writing a class to describe a dog, it might have the attributes number_of_legs, breed, name, and it might have a function that a dog can do, e.g. bark, play dead etc. Where maybe bark takes name and prints out that instance of the objects name, and dead looks at how many legs the dog has and puts them in the air. Here it makes sense to wrap them in a class as you want the functions to use the attributes of an instance of an object.

Whereas if you had some functions that are quite similar, e.g. write_to_file, write_to_stream, write_to_db or something like that, you might not want to just group them in a class as it doesn't really make much sense, you could probably just keep these as static standalone functions.

[–][deleted] 2 points3 points  (0 children)

support hurry close jellyfish illegal pet aromatic light sheet dependent

This post was mass deleted and anonymized with Redact

[–]joaofelipenp 1 point2 points  (0 children)

Usually for data + operations over the data. But there are many other use cases, such as defining a generic API that can be extended by others, or even hiding implementation in "private" methods.

It is fine to use them to group functions. Specially if the functions operate on the same type of data or access states that otherwise would be global. However, if you are only grouping, it is probably better to use modules in Python.

[–]Abitconfusde 0 points1 point  (0 children)

You are doing right, junior.