Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 294 295 [296] 297 298 ... 796

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

SethCreiyd

  • Bay Watcher
  • [VESPERTINE]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4425 on: May 21, 2013, 07:22:09 am »

If the intent was declaring a new class inside a method of an existing class, you can declare it the normal way.

Code: [Select]
>>> class C(object):
    def __init__(self):
        class D(object):
            def __init__(self):
                self.dVar = 5
                print self.__class__, self.dVar
        self.newClass = D()

       
>>> c=C()
<class '__main__.D'> 5


The syntax is no different, just the scope.  Not sure what you were trying to do with 'self', but if you want a neat way to make dynamic classes, you can use the type() built-in.

Code: [Select]
>>> class C(object):
    def __init__(self):
        D = type("D", (object,), dict(dVar=5))
        self.newClass = D()
        print self.newClass, self.newClass.dVar

       
>>> c=C()
<__main__.D object at 0x02664090> 5

Logged

Dutchling

  • Bay Watcher
  • Ridin' with Biden
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4426 on: May 21, 2013, 07:40:29 am »

Wait. I actually DID to it right, I just misspelled something.

I guess I shouldn't have a DATE and a DATA class which I both use a lot Dx.

Thanks for the help though :D
Logged

Rose

  • Bay Watcher
  • Resident Elf
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4427 on: May 22, 2013, 04:30:26 am »

Well, for the last few days I've been working on making some functions that will automatically generate 3d models of roads and intersections with just a few parameters, namely intersection locations, which intersections are connected to which, and the road widths.
I've finally managed to get something working:
Spoiler (click to show/hide)
As you can see, it's not perfect, but at least it's not doing anything obviously wrong, so this makes me happy with it so far.
Logged

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4428 on: May 28, 2013, 05:20:27 pm »

Here's a little C++ tidbit that's come up in my past 2 interviews:
If I have 3 functions,
void Foo1(int, int)
int Foo2()
int Foo3()
and I call them like so:
Foo1(Foo2(), Foo3());
which order do Foo2 and Foo3 run in?

Spoiler: Answer (click to show/hide)
Logged

Levi

  • Bay Watcher
  • Is a fish.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4429 on: May 28, 2013, 06:14:13 pm »

Ha, interesting. 

Spoiler (click to show/hide)
Logged
Avid Gamer | Goldfish Enthusiast | Canadian | Professional Layabout

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4430 on: May 28, 2013, 06:25:57 pm »

Ha, interesting. 

Spoiler (click to show/hide)

That is interesting.

Spoiler (click to show/hide)

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #4431 on: May 28, 2013, 06:51:58 pm »

In the interview I'd make a point to go on a rant that it shouldn't matter, and that in the code the order of them shouldn't matter like that because it means the functions Foo2 and Foo3 have non-obvious and unsafe side-effects, which is very unclean. And also point out that of I encountered code like that, I'd see it as better to feel the pain as soon as I realise it and take the time to refactor the code to not do that, than to leave unclean code in the system and let it cause hidden problems later down the line.

Only time it could be unavoidable is in a third-party library, but still it's unclean and should be dealt with and prevented. Passing function calls inside function calls like that is always asking for trouble and personally I try to never nest function calls like that. It just decreases readability with no benefit.
« Last Edit: May 28, 2013, 07:01:30 pm by MorleyDev »
Logged

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #4432 on: May 28, 2013, 07:00:10 pm »

Double post, oops...to give this some meaning, I'll leave you with a thought:
All code is guilty until proven innocent, unworthy until tested, and pointless without singular and well-defined purpose.
« Last Edit: May 28, 2013, 07:02:02 pm by MorleyDev »
Logged

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4433 on: May 28, 2013, 07:27:11 pm »

In the interview I'd make a point to go on a rant that it shouldn't matter, and that in the code the order of them shouldn't matter like that because it means the functions Foo2 and Foo3 have non-obvious and unsafe side-effects, which is very unclean. And also point out that of I encountered code like that, I'd see it as better to feel the pain as soon as I realise it and take the time to refactor the code to not do that, than to leave unclean code in the system and let it cause hidden problems later down the line.

Only time it could be unavoidable is in a third-party library, but still it's unclean and should be dealt with and prevented. Passing function calls inside function calls like that is always asking for trouble and personally I try to never nest function calls like that. It just decreases readability with no benefit.
Eh, it's the video game industry, so most of the code was written by some variety of third parties, be it CryEngine, Havok, DirectX, Unity, UnrealEngine, ect.
Logged

MadocComadrin

  • Bay Watcher
  • A mysterious laboratory goblin!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4434 on: May 28, 2013, 10:31:13 pm »

Here's a little C++ tidbit that's come up in my past 2 interviews:
If I have 3 functions,
void Foo1(int, int)
int Foo2()
int Foo3()
and I call them like so:
Foo1(Foo2(), Foo3());
which order do Foo2 and Foo3 run in?

Spoiler: Answer (click to show/hide)
I would have answered right-to-left, generalizing that since many C implementations expect arguments on the stack in reverse order (ie, calling printf from assembly code would require pushing the arguments onto the stack from "right-to-left."), and that C++ probably doesn't deviate from C too much in that regard (and can often be compiled to C before being compiled to object code) it would be right-to-left. However; that answer makes sense, as I had picked up the original information from using GCC.
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4435 on: May 29, 2013, 07:17:08 am »

Ha, I knew that one! :)

However, I'm tempted to give up on C++. Moving to a 64bit OS just made my linker choke himself to death on my project and I'm honestly sick and tired of linking-that-is-not-working. I'm going to try me some Unity next.
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4436 on: May 29, 2013, 12:35:03 pm »

Yeah, Unity is great for prototyping 3D games as well as making 3D games which could fall under the category of 'typical.' Games which are edge-cases in terms of code use are its main weakness; anything particularly weird like expansive voxel terrain or such would be problematic, but for typical game systems, it's great. It's also extremely easy to pull in assets like models, animations, textures, and so on. You can have a simple game up and running within a day.
Logged

Rose

  • Bay Watcher
  • Resident Elf
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4437 on: May 29, 2013, 03:26:48 pm »

I've started using Unity, and it's pretty decent so far, and what I'm doing is far from a 'typical' game.

Anything extra besides the basics that you'd need to do in Unity, you'd need to do in your own engine anyway.

Like this stuff:
Spoiler (click to show/hide)
The difference is in Unity it's much quicker to see the result.
Logged

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: if self.isCoder(): post() #Programming Thread
« Reply #4438 on: May 29, 2013, 03:29:41 pm »

So Japa, you trying to do a sim city like engine?
Logged
Take me out to the black, tell them I ain't comin' back...
I don't care cause I'm still free, you can't take the sky from me...

I turned myself into a monster, to fight against the monsters of the world.

GlyphGryph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4439 on: May 29, 2013, 03:29:45 pm »

I hate Unity, personally, but that's mostly because the web player is not cross platform and it seems to be most popular for web stuff. Which fucking sucks.
* GlyphGryph shakes fist.
Logged
Pages: 1 ... 294 295 [296] 297 298 ... 796