Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 538 539 [540] 541 542 ... 796

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

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8085 on: October 06, 2015, 03:50:17 am »

That looks like C#, which is strictly object-oriented. You can't have code outside classes.

Someone got to it before me, but it's def Java.

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8086 on: October 06, 2015, 04:39:37 am »

The idea behind having all code in classes is way more than just simplification. It also adds flexibility in every aspect other than writing code.
Don't you think that statement is contradictory?
My experience is that in many instances using object orientation makes you add tons of boilerplate that could be easily avoided when using some other paradigm which offers everything you need for less code and better readability.

Flexibility comes from having more tools available, not from having one tool which supposedly does everything.
I said "every aspect other than writing code". Compilation, distribution, dynamically loading classes at runtime, these things. And technically, the only negative aspect of forcing everything to be in classes is that you have to write "public static" in front of all your otherwise-global methods and variables.
Logged

Antsan

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8087 on: October 06, 2015, 04:50:48 am »

I don't get how having everything object oriented would make these things more flexible. I'm not even sure how compilation can be "more flexible" (unless you mean programmable compilers, in which case object orientation doesn't help in the slightest).
Common Lisp has dynamic loading of everything, including functions and class definitions. It even can do redefinition of everything at runtime.

Quote
And technically, the only negative aspect of forcing everything to be in classes is that you have to write "public static" in front of all your otherwise-global methods and variables.
No, it also forces you to think in a very specific way about programming. The object metaphor can be pretty imposing and that is a bad thing when you're thinking about something which isn't neatly representable in a class hierarchy.

It's not like the programming world is divided into "functions" and "objects".
Logged
Taste my Paci-Fist

Orange Wizard

  • Bay Watcher
  • mou ii yo
    • View Profile
    • S M U G
Re: if self.isCoder(): post() #Programming Thread
« Reply #8088 on: October 06, 2015, 05:07:57 am »

Personally I quite like having everything in classes, but that's mostly because it appeals to my deranged OCD.

It doesn't make the code any more or less flexible. It makes you think in a specific way about namespaces, which changes how the code is structured on the macro-level but don't really do anything beyond that.

Also, it makes things neater.
Logged
Please don't shitpost, it lowers the quality of discourse
Hard science is like a sword, and soft science is like fear. You can use both to equally powerful results, but even if your opponent disbelieve your stabs, they will still die.

Antsan

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8089 on: October 06, 2015, 06:22:19 am »

It makes you think in a specific way about namespaces, which changes how the code is structured on the macro-level but don't really do anything beyond that.
Seeing how there's stuff beyond classes and functions in other languages, I'd say you're wrong. Of course most language don't make use of anything but data structures and functions.

If you like neat code, try Haskell some time. You'll look at OOP and wonder how you could ever think it was neat.
Logged
Taste my Paci-Fist

LoSboccacc

  • Bay Watcher
  • Σὺν Ἀθηνᾷ καὶ χεῖρα κίνει
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8090 on: October 06, 2015, 07:16:36 am »

more a case of having this or that particular hammer.

look a piece of code has normally 4 ports:

- a data on stack coming from above
- b data you put on stack for code below you (includes returns)
- c data that sits on the heap
- d data that sits remotely (disk, db, stuff)

a programming style is mostly about managing the complexity of this.

oop has a thing for partitioning the heap, so that a method only has to deal with minimal c, you know everything that touches a particular subset of c, and thus you mostly care about a and b - possibly you limit complexity with only taking two port at once (like, a dao class would work with a and d or b and d, but not c) but that's just good habit and optional to the style.

functional programming is mostly focusing on having everything flowing from a to b with minimal impact from other ports to minimize complexity of processing data, and treats c and d mostly as start/end of a particular code flow

the language you code in doesn't really prevent you to use this or that style. heck I've seen beautiful oop design in c.

the more you think about code and data flow, the less you need to take on a particular style as a religion, as opposed to use the one that solves the problem at hand more easily (many complex data structure in memory? many transformation to be done on a large dataset? need to handle multiple synchronized updates on many datasources?)

Logged

Orange Wizard

  • Bay Watcher
  • mou ii yo
    • View Profile
    • S M U G
Re: if self.isCoder(): post() #Programming Thread
« Reply #8091 on: October 06, 2015, 09:30:26 am »

If you like neat code, try Haskell some time. You'll look at OOP and wonder how you could ever think it was neat.
Could you say it's...
* Orange Wizard puts on sunglasses
Objectively better?

More seriously, OOP vs. not-OOP boils down to personal preference. S'not really a big deal.
Logged
Please don't shitpost, it lowers the quality of discourse
Hard science is like a sword, and soft science is like fear. You can use both to equally powerful results, but even if your opponent disbelieve your stabs, they will still die.

Moghjubar

  • Bay Watcher
  • Science gets you to space.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8092 on: October 06, 2015, 10:26:31 am »

Not quite, especially in cases where you need optimization, you have to break OOP practices (while few people these days gain benefit and work with low level... and most programs wouldn't get written if they all had to be that low... the savings from a properly optimized program are tremendous)
Logged
Steam ID
Making things in Unity
Current Project: Demon Legend
Made This too (publisher abandoned ) Farworld Pioneers
Mastodon

jaked122

  • Bay Watcher
  • [PREFSTRING:Lurker tendancies]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8093 on: October 06, 2015, 11:21:51 am »

Besides, you can do non-oop in java. It just results in static classes, methods, attributes, etc. Make them public and they are very nearly the same as declaring a global variable or function. It's just less convenient to call them. More text.

i2amroy

  • Bay Watcher
  • Cats, ruling the world one dwarf at a time
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8094 on: October 06, 2015, 11:38:26 am »

Not quite, especially in cases where you need optimization, you have to break OOP practices (while few people these days gain benefit and work with low level... and most programs wouldn't get written if they all had to be that low... the savings from a properly optimized program are tremendous)
Except so much work has been done on the C/etc. compilers that in the vast majority of cases the compiler will be able to optimize even unoptimized code beyond anything you could do. I don't have the link here, but I remember at least one article I've read before by a compiler guru who pointed out that in many cases when you are working in C or C++ we've reached the point where your manual optimizations in lots of cases end up actually slowing down the code because the compiler has to bend over backwards to jump through the "optimization" hoops that you set up rather than just using the best optimized solution.

It's not always true, of course, but compilers are starting to get smart enough to be able to optimize your logic much better than you ever could manually these days, and that's only becoming more true as time passes and people put ever more amounts of work to do that.

Funnily enough, in a fair number of cases this also applies to an advantage of higher level languages over lower level ones, since it lets the compiler do more optimizations that have been laboriously compiled over the years, rather than forcing you to manually program in what you (hope) is the best optimization of them all. (Of course this is countered somewhat by the fact that lower level languages have been around longer and thus in general tend to have better compilers, but it's still something to keep in mind).
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.

Gatleos

  • Bay Watcher
  • Mournhold... City of Light... City of MAGIC!
    • View Profile
    • Someone Sig This
Re: if self.isCoder(): post() #Programming Thread
« Reply #8095 on: October 06, 2015, 12:49:17 pm »

Man SFGUI is really sparse on documentation. I've been trying to connect a callback function to an "OnExpose" event, which is supposed to trigger every time a GUI element is rendered... but it doesn't. I've already seen the authors of the library telling a confused user that some things in the library aren't fully implemented, as if that makes it okay for the library to not TELL you this. Now I'm wondering if that's the case here.

GUI programming is hard. :'(
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

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8096 on: October 06, 2015, 08:28:21 pm »

Not quite, especially in cases where you need optimization, you have to break OOP practices (while few people these days gain benefit and work with low level... and most programs wouldn't get written if they all had to be that low... the savings from a properly optimized program are tremendous)
Except so much work has been done on the C/etc. compilers that in the vast majority of cases the compiler will be able to optimize even unoptimized code beyond anything you could do. I don't have the link here, but I remember at least one article I've read before by a compiler guru who pointed out that in many cases when you are working in C or C++ we've reached the point where your manual optimizations in lots of cases end up actually slowing down the code because the compiler has to bend over backwards to jump through the "optimization" hoops that you set up rather than just using the best optimized solution.

It's not always true, of course, but compilers are starting to get smart enough to be able to optimize your logic much better than you ever could manually these days, and that's only becoming more true as time passes and people put ever more amounts of work to do that.

This is all true and something that I live by.  It does remind me of an interesting anecdote from recent experience though.  I was surprised to discover that GCC 4.8 at least isn't able to optimize a simple for loop that checks the .size() condition of a vector or similar standard library class so that the .size() check is moved out of the loop condition and replaced with a simple cached copy of the value.  That is,

Code: [Select]
vector<int> something;

// Insert a lot of things into something

for (unsigned int i = 0; i < something.size(); i++) {
    // Do things
}

should be translated to something like:

Code: [Select]
vector<int> something;

// Insert a lot of things into something

unsigned int size = something.size();

for (unsigned int i = 0; i < size; i++) {
    // Do things
}

The reason, of course, is that the compiler doesn't know easily if the loop body changes something that would cause .size() to return a different value.  Even with relatively simple code that only reads from the vector though, it won't treat the size as an invariant.  I've actually saved several % runtime in a computationally heavy program by performing that optimization manually.
Logged
Through pain, I find wisdom.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8097 on: October 07, 2015, 04:04:34 am »

Has anyone used the Box2D library in C++. I need to get this hooked up in an SFML demo by tomorrow, and nothings actually moving so I don't know where to start. I made a body, added the stuff listed in the tutes, apply a force and step forward in the world each frame, but there's no visible effect on the object I'm trying to move.

monkey

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8098 on: October 07, 2015, 09:26:49 am »

Is the object's density non-zero ?
Logged

jaked122

  • Bay Watcher
  • [PREFSTRING:Lurker tendancies]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8099 on: October 07, 2015, 09:42:32 am »

Has anyone used the Box2D library in C++. I need to get this hooked up in an SFML demo by tomorrow, and nothings actually moving so I don't know where to start. I made a body, added the stuff listed in the tutes, apply a force and step forward in the world each frame, but there's no visible effect on the object I'm trying to move.
This sounds like a silly issue.


After each step do you update the coordinates of the sfml objects that are represented in the box2d objects, those don't seem to be coupled normally, so perhaps you ought to update the positions of your drawing primitives to the positions of your physics primitives.


Sorry that I can't be more specific, but that sounds like the sort of problem I would have. Is that it?
Pages: 1 ... 538 539 [540] 541 542 ... 796