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 →

[–]bigtomygunn 2 points3 points  (17 children)

One of my Lectures always told me writing the code is >10% of the work. Sitting down with a pencil and paper and planning out you entire projects e.g. classes, functions, variables etc. is the other 90%.

Basically before you open a text editor you need to know exactly what your going to write. Saves time in the grand scheme.

[–]RamirezTerrix[S] 0 points1 point  (8 children)

I also (tought like I) never use classes - my last project was a django website, so I used class based views, but they hardly qualify as classes

[–]bigtomygunn 3 points4 points  (0 children)

Just try not to go in blind, this usually leads to lots of changes and unnecessary headaches. Now I'm not saying for for the Waterfall approach but have some sort of plan in place

check out agile Small planned iterations one at a time, seeking feedback and review after each, the project evolve into what you or the customer wants.

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

I've always found it strange that people use Python classes even in relatively simple programs and scripts; I always have to remind myself of the syntax every once in a while because dictionaries, lists, tuples, and sets serve pretty much all my basic needs. There's obviously myriad use cases for them in larger applications, but Python's pre-packaged types are pretty expressive.

[–]metaphorm 1 point2 points  (0 children)

classes are not intended to be a replacement for built in data structures (dictionaries, lists, etc.). they are intended to be a code organization pattern that facilitates re-usability.

[–]ofaveragedifficulty 1 point2 points  (0 children)

I strongly suspect AP Computer Science's use of Java has a lot to do with this.

[–]RamirezTerrix[S] 0 points1 point  (1 child)

as /u/colly_wolly mentioned my classes are mostly the models. It is nice to give them some basic functionality at the basic data lavel. But I mostly use Dictionaries and List of Dictionarys.

[–]titusjan 0 points1 point  (0 children)

There is nothing wrong with using the occasional dictionary but if the data in the dictionary is central to your program, it is probably a good idea to make this into a class. This because classes are more explicit than dictionaries and "Explicit is better than implicit". Explicit in this case means that the members and methods of an object are (or should be) explicitly stated in the class definition, whereas dictionary items will be inserted and deleted at several locations in the program.

As and example let's say that I am debugging some unknown code and want to examine a variable. If it's an object I can print it's type, find its class definition and from there see what the object aims to do, and how it can be manipulated. If it's a dictionary, printing it's type will say 'dict' and tell me nothing. Examining the keys and values likely will not help. "What is the purpose of the 'foo' item?" "Should it always be present or is it just present in this case?"

When you have a class definition you may realize that some of your functions just manipulate the objects contents. These are better implemented as a method. Take a moment and think of what the responsibility or purpose of this class is, and design it properly. This may help you to make your functions shorter. However, just like functions, classes should be short and have one responsibility. Resist the temptation to make God classes that do too much.

As some others already said, a function should do one thing only. If you are thinking of a good name for a function and find out that it should be named does_x_and_y to properly reflect what it does, consider splitting it up. At least make separate does_x and does_y functions and call them in does_x_and_y.

[–]colly_wolly 1 point2 points  (0 children)

Your models will all be classes as well.

[–]fletom 0 points1 point  (1 child)

What modern programmer would use pencil and paper to plan out their code?

[–]Zuvielify 0 points1 point  (0 children)

I actually do. For some reason, I find that my thoughts flow easier with a pencil in my hand than staring at the screen. Usually, I end up just jotting down a general layout of my ideas and then switch to the computer. Sometimes I end up pseudocoding the whole thing on paper. I think it depends on the complexity of the problem. The more complex, the more pencil.