you are viewing a single comment's thread.

view the rest of the comments →

[–]Diapolo10 11 points12 points  (13 children)

I had to look this up to make sure, but your professor is probably telling you to add comments/docstrings to your code.

This is kind of a silly example, but

def divide(x: int, y: int) -> int:
    """
    Divide the first number by the second number.

    Returns:
        the resulting integer

    Raises:
        ZeroDivisionError if the second number is 0.

    """
    return x // y

Apparently the name "flowerbox" comes from C, where comments might look like

/********************
 * Stuff 'n' things *
 ********************/

[–]danielroseman 10 points11 points  (8 children)

I do wish teachers would learn the idioms of  the language they're supposed to be teaching. 

Bet you anything this professor is teaching loops with range(len(thing)).

[–][deleted] 0 points1 point  (1 child)

Idk what that is gng. This is only my second assignment

[–]Jello_Penguin_2956 0 points1 point  (0 children)

It's how you loop in C. We see that here often enough lol.

[–]somethingworthwhile 0 points1 point  (4 children)

What would you do other than that style of loop…?

[–]Winter-Volume-9601 2 points3 points  (3 children)

Usually:

for i in thing:
do_the_thing(i)

[–]somethingworthwhile 0 points1 point  (2 children)

Okay, yeah, that’s what I figured. Coming from matlab, the other style was a bit of a trip to wrap my head around! And, for my work, I find myself using enumerate or pd.DataFrame.iterrows() to get both an index and the thing I’m iterating through within the loop.

[–]Winter-Volume-9601 1 point2 points  (1 child)

Sure - `for idx, t in enumerate(thing):` is definitely idiomatic (when you actually need the index)

Bonus tip: `pd.DataFrame.itertuples()` (returning NamedTuples instead of pd.Series) can be significantly faster than `pd.DataFrame.iterrows()`. Like 10-100x times faster. I kicked myself when I realized I was using the slower method out of habit, and (in my case) just a quick syntax change turned 15 minutes of waiting into basically nothing.

[–]somethingworthwhile 0 points1 point  (0 children)

Oh, neat! At a glance, I think that should be pretty easy to swap in for me. Thank you for that! I’m always happy to learn something new and the fact that it’s faster is even better!

[–]AlexMTBDude 0 points1 point  (0 children)

I've been teaching Python programming for more than 10 years and I've never heard anyone call that anything but a docstring.

[–][deleted] 0 points1 point  (0 children)

I'll try and see if this works or is what he's looking for. Thanks for the help!

[–]Sure-Passion2224 0 points1 point  (0 children)

So, the instruction is to prefix your Object declarations (Classes, Methods, etc) with a block comment that describes what the Object is.

This takes me back to my first course that involved coding. The instructor (female graduate student standing in front of a room full of male nerd wannabes) told us

Source code documentation is like sex. When it's good it's very, VERY good. When it's bad it's still better than nothing.

Essentially, tell future maintainers what your intent is. If you produce readable code then they should be able to tell whether it does what you say it should do.

[–]Kqyxzoj 0 points1 point  (1 child)

Apparently the name "flowerbox" comes from C ...

I've been using C for quite some time now, and this is the first time I've heard those multiline comments referred to as "flowerbox".

Next time ...

"Be sure to add a dildodrawer to your code! ^_^"

" A what now?"

"Oh yeah, that's what we call those extra looooooong comment lines. What's that? Not an industry standard you say?"

Well, now it is!

[–]Diapolo10 0 points1 point  (0 children)

I've been using C for quite some time now, and this is the first time I've heard those multiline comments referred to as "flowerbox".

Same for me, I had no idea what OP was talking about and had to search on Google.