Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


#ActualKylotan

Posted 21 January 2013 - 09:26 AM

However, I have yet more code that is copied. (DRY principle is once more violated).
So, after picking an idea from the pdf on meerkat, I thought about this:
http://www.pasteall.org/38988/python

It's the same idea; using environment flags (which I haven't exposed in the examples) to suppress method calls if they are incorrect.

Is this an acceptable solution? Can you see any inconveniences that I've not?
In my experience this is a bad idea. Imagine that file is 10x the size. When you look at shoot() you don't know if shoot_sounds() is going to do anything or not without having to inspect that too. That's going to hurt maintainability and debugging later.

I personally would prefer either a clear separation of client and server functionality or clearly labelled functionality inline. eg.
if self.is_client(self.shoot_sounds()). Explicit is better than implicit.

Or, if you don't want conditionals in the code, make it event-driven. Emit a 'shoot' event and clients and servers can decide how to handle the events in a way relevant to them. It's still fairly opaque compared to explicit conditionals, but at least you'd know that all the server/client specific behaviour is encapsulated in the event system.

EDIT: I would love it if this editor didn't completely break the formatting half the time.

#2Kylotan

Posted 21 January 2013 - 09:25 AM

<blockquote class="ipsBlockquote" data-author="Angus Hollands" data-cid="5023520"><p>However, I have yet more code that is copied. (DRY principle is once more violated).<br />So, after picking an idea from the pdf on meerkat, I thought about this:<br /><a data-cke-saved-href="http://www.pasteall.org/38988/python" href="http://www.pasteall.org/38988/python">http://www.pasteall.org/38988/python</a><br /><br />It's the same idea; using environment flags (which I haven't exposed in the examples) to suppress method calls if they are incorrect.<br /><br />Is this an acceptable solution? Can you see any inconveniences that I've not?</p></blockquote>In my experience this is a bad idea. Imagine that file is 10x the size. When you look at shoot() you don't know if shoot_sounds() is going to do anything or not without having to inspect that too.<br /><br />I personally would prefer either a clear separation of client and server functionality or clearly labelled functionality inline. eg.<br />if self.is_client(self.shoot_sounds()). Explicit is better than implicit.<br /><br />Or, if you don't want conditionals in the code, make it event-driven. Emit a 'shoot' event and clients and servers can decide how to handle the events in a way relevant to them. It's still fairly opaque compared to explicit conditionals, but at least you'd know that all the server/client specific behaviour is encapsulated in the event system.<br />

#1Kylotan

Posted 21 January 2013 - 09:24 AM

<blockquote class="ipsBlockquote" data-author="Angus Hollands" data-cid="5023520"><p>However, I have yet more code that is copied. (DRY principle is once more violated).<br />So, after picking an idea from the pdf on meerkat, I thought about this:<br /><a data-cke-saved-href="http://www.pasteall.org/38988/python" href="http://www.pasteall.org/38988/python">http://www.pasteall.org/38988/python</a><br /><br />It's the same idea; using environment flags (which I haven't exposed in the examples) to suppress method calls if they are incorrect.<br /><br />Is this an acceptable solution? Can you see any inconveniences that I've not?</p></blockquote>In my experience this is a bad idea. Imagine that file is 10x the size. When you look at shoot() you don't know if shoot_sounds() is going to do anything or not without having to inspect that too.<br /><br />I personally would prefer either a clear separation of client and server functionality or clearly labelled functionality inline. eg.<br />if self.is_client(self.shoot_sounds()). Explicit is better than implicit.<br /><br />Or, if you don't want conditionals in the code, make it event-driven. Emit a 'shoot' event and clients and servers can decide how to handle the events in a way relevant to them. It's still fairly opaque compared to explicit conditionals, but at least you'd know that all the server/client specific behaviour is encapsulated in the event system.<br />

PARTNERS