Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 604 605 [606] 607 608 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 884658 times)

i2amroy

  • Bay Watcher
  • Cats, ruling the world one dwarf at a time
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9075 on: February 16, 2016, 01:50:58 pm »

Of course, all of this ignores the very useful lesson of "don't try and future-proof before there's even a future to protect".
I think that, like many things else, this isn't necessarily a hard extreme rule. In many cases taking just a small amount of time and work now can create a huge amount of future proofing that you save later. Defining your weight unit in grams and your volume unit in milliliters now while you are designing the system can save you tremendous amounts of work as opposed to having to go back months from now, dig up every spot the units have been used in the code and add a multiplication factor because you started with lbs and liters and you need more granularity in your system. This is not to say that you should take the idea to the extremes, of course, but I find that taking 5 to 10 minutes to consider how you could future proof an application before you actually start implementing it (at which point you should already have drawn out a plan and know what you are going to be trying to implement, at least) is almost always worth more time in the long run than not considering the future at all.
Logged
Quote from: PTTG
It would be brutally difficult and probably won't work. In other words, it's absolutely dwarven!
Cataclysm: Dark Days Ahead - A fun zombie survival rougelike that I'm dev-ing for.

breadman

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9076 on: February 16, 2016, 02:40:42 pm »

Some of the better examples of subclassing seem to usually be basically interface - implementation cases. Eg, python's unittest module, or XNA's Game class where you can hook up your onRender, onUpdate events and let the rest of the engine handle everything else.
I suspect that you're on to something here.  Inheritance trees are often set up to reduce code duplication by moving common functionality into base classes, but in most cases only the leaf nodes are expected to be instantiated.  There are exceptions, but they're more for convenience or compatibility than philosophy.

Consider Python's queue module.  LifoQueue and PriorityQueue inherit from Queue, but only because they can use the same interface and most of the same code.  I'm guessing Queue was introduced first; otherwise, LifoQueue could have been named Stack, and they may both have inherited from some abstract ThreadSafeContainer class.

But considering the community, a better example may be DF's own items.  We have an abstract item class with much of the code, with subclasses for certain groups of item types, such as a class for items that get constructed in a workshop, and another for body components.  But actual items in the game are instances of the leaf nodes in this class hierarchy, like metal bars, or gems, or eggs, or cages.  The base item class is the interface, and these leaf nodes are the implementations.

(Granted, some of the apparent implementation baffles me.  I'd expect to find a class for wearable items, one for edible items, and one for containers, but there may be something about either the code or its history that makes the current system more sensible.  Then again, I had a similar thought when looking at NetHack's code.  I have never seen more switch statements in a single codebase.)

We can learn a lot here from how relational databases do things. With poorly planned OOP sometimes we invent overly-complex "solutions" that have very obvious flaws, which already have perfectly working solutions in the database world. You can implement the same patterns in your code.
Many of my projects lately have started from the perspective that each table gets its own class, responsible for most of the behavior logically associated with that data.  That's not always ideal, but is certainly a convenient starting point.  For classes without associated database tables, it's all about code reuse.  If a class provides most of what I need, but isn't quite right, subclassing is always an option (as long as it's less work than modifying, re-implementing, or wrapping), even if the resulting class hierarchy doesn't look good from an architectural standpoint.
Logged
Quote from: Kevin Wayne, in r.g.r.n
Is a "diety" the being pictured by one of those extremely skinny aboriginal statues?

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9077 on: February 16, 2016, 03:27:07 pm »

(Granted, some of the apparent implementation baffles me.  I'd expect to find a class for wearable items, one for edible items, and one for containers, but there may be something about either the code or its history that makes the current system more sensible.[...])
The container thing is perfectly sensible, since the container system also handles contaminations and every item needs to be contaminable. The wearable and edible item thing is also perfectly sensible as it is, since wearability and edibility are attributes of the item type, not the item itself.
Logged

DJ

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9078 on: February 16, 2016, 03:59:23 pm »

What about component-based systems? Those seem to be fairly popular in game dev. So you could have a person that can have a student and/or a teacher component. If student/teacher can only be attached to a person, it's guaranteed that you'll have person behavior available for all your students and teachers.
Logged
Urist, President has immigrated to your fortress!
Urist, President mandates the Dwarven Bill of Rights.

Cue magma.
Ah, the Magma Carta...

miauw62

  • Bay Watcher
  • Every time you get ahead / it's just another hit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9079 on: February 16, 2016, 04:11:44 pm »

Component Entity System is a cool paradigm, yeah. And probably amongst the best for complex games like DF and SS13 that strive for lots of dynamic interactions between objects
Logged

Quote from: NW_Kohaku
they wouldn't be able to tell the difference between the raving confessions of a mass murdering cannibal from a recipe to bake a pie.
Knowing Belgium, everyone will vote for themselves out of mistrust for anyone else, and some kind of weird direct democracy coalition will need to be formed from 11 million or so individuals.

Antsan

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9080 on: February 16, 2016, 04:25:17 pm »

All this talk about inheritance and OOP and subclassing just reminds me of this great blog post from one of the programmers of The Witness.
I largely agree with him, but this here sticks out:
Quote
I like “compress” better as an analogy, because it means something useful, as opposed to the often-used “abstracting”, which doesn’t really imply anything useful. Who cares if code is abstract?
I like abstraction, even if I am not already using the code in question in two places. The problem lies in the amount of information to juggle at any point during programming.
As far as I am able to tell I've got really bad short term memory. I can't hold many things in my head at once. If I read a section of code longer than two to five lines (depending on language) (excluding declarations/variable definitions) I tend to loose track. Thus I try to cut anything I need to do down to one or two lines. One tool to do that is called abstraction – I give some process a name, thus making it easily handleable as one concept and thus cut down on the things I need to keep track of while trying to understand what a certain piece of code is doing.
The same goes for nesting, although it's normally less pronounced there – many branches in the AST are worse than long branches.

Ironically the languages where I can keep track of more lines at once are normally those that tend to need fewer of them.
Logged
Taste my Paci-Fist

miauw62

  • Bay Watcher
  • Every time you get ahead / it's just another hit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9082 on: February 16, 2016, 07:27:08 pm »

After reading that article, the dude falls into the same trap as the things he's so relentlessly bashing: advertising his way as the One True Way. Everything else is dumb because [insert clever purely theoretical reasoning here].

Having a general idea of how I'm going to handle something beforehand is very useful to me, for example.
Logged

Quote from: NW_Kohaku
they wouldn't be able to tell the difference between the raving confessions of a mass murdering cannibal from a recipe to bake a pie.
Knowing Belgium, everyone will vote for themselves out of mistrust for anyone else, and some kind of weird direct democracy coalition will need to be formed from 11 million or so individuals.

EnigmaticHat

  • Bay Watcher
  • I vibrate, I die, I vibrate again
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9083 on: February 16, 2016, 08:12:32 pm »

EnigmaticHat:That doesn't make sense.  An object containing all the enemies is a rather useless thing because you still have to code the enemies and you'd be re-implementing arrays.  And the enemies are objects. 
And Mario is an object, not a primitive type.  He's got stuff he does and states to store.
...yeah, so funny story.  While trying to explain objects and classes I said object while I meant to say class (as in, I meant enemy class).  Whoopsie...
Logged
"T-take this non-euclidean geometry, h-humanity-baka. I m-made it, but not because I l-li-l-like you or anything! I just felt s-sorry for you, b-baka."
You misspelled seance.  Are possessing Draignean?  Are you actually a ghost in the shell? You have to tell us if you are, that's the rule

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9084 on: February 16, 2016, 09:59:18 pm »

Oop.  Or OOP.
Logged
Sigtext

It has been determined that Trump is an average unladen swallow travelling northbound at his maximum sustainable speed of -3 Obama-cubits per second in the middle of a class 3 hurricane.

LoSboccacc

  • Bay Watcher
  • Σὺν Ἀθηνᾷ καὶ χεῖρα κίνει
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9085 on: February 17, 2016, 02:22:25 pm »

I can't hold many things in my head at once. If I read a section of code longer than two to five lines (depending on language) (excluding declarations/variable definitions) I tend to loose track. Thus I try to cut anything I need to do down to one or two lines. One tool to do that is called abstraction


I'd call it information hiding, a subcategory of abstraction, and yes, I live by it, because when you get 1m line of code mixed between javascript, java, install scripts and mobile wrapper remembering that to create Baa() you first need to call Foo() because it initializes a variable Baa needs is the road to madness.

Same with code passing strings around. a method that tells me that the input is a Regex instead of a String is 10x more robust when I have to fix something ten months down the line. 
« Last Edit: February 17, 2016, 02:24:36 pm by LoSboccacc »
Logged

Cryxis, Prince of Doom

  • Bay Watcher
  • Achievment *Fail freshman year uni*
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9086 on: February 17, 2016, 02:30:23 pm »

GUESS WHO FINALLY GOT THE FREAKING ELEVATOR TO WORK?!?

My group partner (groups of two, he's making a 3D model of our robot) and I named the robot "Wheatly" because it is a moron.
Logged
Fueled by caffeine, nicotine, and a surprisingly low will to live.
Cryxis makes the best typos.

Mephisto

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9087 on: February 17, 2016, 02:52:27 pm »

Story time. I feel like telling a short mystery. See if you can come to the proper conclusion before my story ends.


For the past two days, I've been fighting with a server. It's under the correct security group on AWS. I can ssh into it by ip and by ec2 hostname. I cannot, however, ssh into it using the domain I assigned to it in Route 53. Hitting the server on port 80 throws up the default Apache error page. As this server only has Nginx on it, I take that as a good sign - it's merely a load balancer pointing to things that have Apache on them. The load balancer isn't logging traffic, though. Not in access.log or error.log. None of the web servers are showing hits in their Apache logs either.

Curious. I'm getting an Apache error page but I'm not hitting the Apache I thought I was hitting. Add an explicit 418 to my nginx config just to be super sure I'm hitting the correct server. I see no 418s being returned, however.

Pull out dig and fish around a bit. "dig +short foo.bar.com" returns the correct ip. I check some other subdomains and they all return the correct ips.

Fast forward to about half an hour ago, I'm idly Googling around. I then see one word, in a context completely unrelated to my problem - "hosts". I check my hosts file. "foo.bar.com" was pointing to localhost and dig apparently ignores that when resolving names. I'm resisting the urge to headdesk repeatedly.

Is it Friday yet?
« Last Edit: February 17, 2016, 03:02:08 pm by Mephisto »
Logged

Gatleos

  • Bay Watcher
  • Mournhold... City of Light... City of MAGIC!
    • View Profile
    • Someone Sig This
Re: if self.isCoder(): post() #Programming Thread
« Reply #9088 on: February 17, 2016, 05:04:35 pm »

So I was looking for a desktop program that could alert me when certain twitch.tv channels started streaming, and every one I could find was also bloated with a billion other unrelated features, like an actual stream viewer. I don't want any of that, so I decided to make my own in Python. It actually only took me a few hours to find a twitch api binding for Python, wrangle the win32gui module into making a little system tray icon that would make popup notifications, and tell it to query channels and display their ticker info.

That was a surprisingly pleasant experience, I was expecting days of frustration. Thanks Python. :P
Logged
Think of it like Sim City, except with rival mayors that seek to destroy your citizens by arming legions of homeless people and sending them to attack you.
Quote from: Moonshadow101
it would be funny to see babies spontaneously combust
Gat HQ (Sigtext)
++U+U++ // ,.,.@UUUUUUUU

Parsely

  • Bay Watcher
    • View Profile
    • My games!
Re: if self.isCoder(): post() #Programming Thread
« Reply #9089 on: February 17, 2016, 05:14:10 pm »

So I was looking for a desktop program that could alert me when certain twitch.tv channels started streaming, and every one I could find was also bloated with a billion other unrelated features, like an actual stream viewer. I don't want any of that, so I decided to make my own in Python. It actually only took me a few hours to find a twitch api binding for Python, wrangle the win32gui module into making a little system tray icon that would make popup notifications, and tell it to query channels and display their ticker info.

That was a surprisingly pleasant experience, I was expecting days of frustration. Thanks Python. :P
Mind sharing it when it's done? I know I'd like it.
Logged
Pages: 1 ... 604 605 [606] 607 608 ... 796