LOADING: An error occurred. Update Chrome, try Firefox, or visit this post for more details.

⚠️Reddit changed how removals work, which breaks Reveddit's website. Install the extension to track removed content:Add to chromeAdd to firefoxWhat changed?
✖︎
about reveddit
⚙F.A.Q.add-ons
r/
status
copy sharelink
[+] show filters
7
Help/QuestionOOP vs Functional(self.adventofcode)
submitted 2 years, 10 months ago by [deleted] to /r/adventofcode (134.8k)
43 commentsredditother-discussionssubreddit-indexmessage mods

I have been dabbling in Python for some time now and have written some really easy apps. But I alway...

... view full text

since 2 years, 10 months ago
16 of 16

Tip Reveddit Real-Time can notify you when your content is removed.

your account history
(check your username's removed content. why?)
Tip Check if your account has any removed comments.
view my removed comments
you are viewing a single comment's thread.
view all comments
[–]imp0ppable15 points2 years, 10 months ago

TBH for this kind of coding I tend to do everything as data. Python is excellent for that.

Dicts or tuples instead of classes, don't need a formal definition of what's in it if you're the only one using it.

e.g.

class Point():
    self.x = 0
    self.y = 0

Is overkill, just use a tuple:

p0 = (0,0)

Just my 2 cents!

permalinkhide replies (5)author-focusas-ofpreserve
[–]IvanOG_Ranger8 points2 years, 10 months ago

If you needed 3d coordinates, would it he just your 3 cents?

permalinkparentcontextauthor-focusas-ofpreserve
[–]Background-Vegetable3 points2 years, 10 months ago

I ALWAYS mix up x and y if I don't name them something.x and something.y

permalinkparentcontexthide replies (4)author-focusas-ofpreserve
[–]imp0ppable9 points2 years, 10 months ago

Really? it's always x first. Although I do unpack them sometimes like

x,y = point

since point[0] and point[1] is quite ugly if you do it multiple times.

permalinkparentcontexthide replies (2)author-focusas-ofpreserve
[–]didzisk25 points2 years, 10 months ago

it's always x first

Except when it's row, column. Except when using A1 notation in Excel. But then, everything is a date in Excel.

Just my Jan 02.

permalinkparentcontexthide replies (2)author-focusas-ofpreserve
[–]grnngr9 points2 years, 10 months ago

You can assume that Excel will consistently behave in the way you least expect it to.

permalinkparentcontextauthor-focusas-ofpreserve
[–]imp0ppable3 points2 years, 10 months ago

I felt this comment in my bones lol

permalinkparentcontextauthor-focusas-ofpreserve
[–]Background-Vegetable1 point2 years, 10 months ago

Except that input[y][x] gives the value for (x,y). I have spent sooooo many hours looking for an error caused by this, I now always take the 3 seconds it takes to make it a Coordinate(x, y) instead of something generic.

permalinkparentcontexthide replies (1)author-focusas-ofpreserve
[–]bleachisback1 point2 years, 10 months ago

I mean you’re the one making the array, nothing is stopping you from making it input[x][y]. It’s just an indexing scheme.

permalinkparentcontexthide replies (1)author-focusas-ofpreserve
[–]Background-Vegetable1 point2 years, 10 months ago

Exactly. That's why I mix them up.

permalinkparentcontextauthor-focusas-ofpreserve
[–]oskrawr3 points2 years, 10 months ago

I’ve given up on using x and y in favor of a rows/cols terminology, with a point being (r, c). Rows naturally comes before cols in spoken language, and also when looping over a matrix.

Edit: and (i, j, k) for three dimensions.

permalinkparentcontextauthor-focusas-ofpreserve
[–]brandonchinn1781 point2 years, 10 months ago

Could always use NamedTuples too!

permalinkparentcontextauthor-focusas-ofpreserve
[–]root421 point2 years, 10 months ago

That’s why I usually use maps in Clojure for that exact reason. You can still throw in whatever you like, but have a bit more structure.

permalinkparentcontextauthor-focusas-ofpreserve
[–]boowhitie1 point2 years, 10 months ago

I would agree for a one off, but for AoC you will often find yourself doing the same thing again. Having a library of tools is very helpful and you can add or update it as you go. OO can help by using subclassing to keep solution specific code in the solution for a single day.

If I do use something like a tuple in a solution, i'll often look over the code and see if refactoring it into a proper object seems like something that would make it useful to other solutions and/or would have gotten me to a solution quicker.

permalinkparentcontextauthor-focusas-ofpreserve
[–]potofpetunias24561 point2 years, 10 months ago

You're completely correct about that.

But I find doing the overkill structure is a great way to familiarize yourself with a new language and the aspects of it you'd use in a larger project.

Frequently I'll read a task and think "Oh, that'll be easy with an array of tuples", but I'll actually decide to solve it with some more complex structures or language features that would be used for that sort of problem in a larger project.

permalinkparentcontextauthor-focusas-ofpreserve
[–][deleted]1 point2 years, 10 months ago

I mainly work with realtime dataframes up to the length of 80k rows updated by the second.

permalinkparentcontextas-of
r/revedditremoved.substack.com
🚨 NEWS 🚨
✖︎

Important: Reddit Changed How Removals Work

A recent Reddit update makes mod-removed content disappear from profile pages, which breaks Reveddit's website.

Install the browser extension to receive removal alerts.

Add to chromeAdd to firefox

What changed?

r/revedditremoved.substack.com