Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 217 218 [219] 220 221 ... 796

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

Forums User Meat Wizard

  • Bay Watcher
  • meet whiz
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3270 on: October 28, 2012, 07:43:45 am »

I'd say hating Eclipse is a pretty reasonable sign that you're an intelligent person in the first place and are certainly smart enough to not need it. I'm not one of those CLI FOR EVERYTHING ARGH guys but I find more and more what I look for in an IDE is less and less.

But then I'm a dirty Python guy so it's hard not to swoon when compiling is something that you largely ignore.
Logged

Killjoy

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3271 on: October 28, 2012, 07:45:30 am »

TSTwizby, you're not alone. I though "I" was alone for the same reason, for the longest time, though. Figuring that out was the single hardest part of programming, and why I started favouring flash and interpreted languages. I don't know if the problem is common and well-hidden, or if there's just a subset of the population that has some natural resistance to figuring it out. :P

It's why I still prefer languages like Ruby, that make handling library management and compiling exceptionally easy.

But for C++, the easiest time was definitely as mentioned above - dropping the IDE approach completely, and just compiling on the command line. Hell, the biggest benefits were that, unlike with the IDEs, there are places you can go that will actually explain how command line compiling works and how to do it.

I'll admit that this is probably the biggest reason I hate Eclipse, for example. I'd spend more time trying to figure out compiling than any other thing I did with.
Eclipse is a very bad IDE for anything not Java in my experience.
That said, c++ is a funny language. I have actually only found one IDE which works very well with it. That is visual studio 2010 (Stay away from the 2012 version). Using libraries is easy once you get into the whole adding directories thing.
But honestly the biggest reason to use VS2010 is for debugging. I do not know if you have ever worked with very big projects. I am talking millions of lines of company code here. Debugging in VS2010 is easy, and you can scope directly into into datastructures, variables and even directly into raw memory to see where things are going wrong, and the profiling tools makes finding performance bottlenecks easier than ever. That said, you are right, most IDEs for coding C++ simply suck.
Logged
Merchants Quest me programming a trading game with roguelike elements.

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3272 on: October 28, 2012, 03:41:07 pm »

TSTwizby, you're not alone. I though "I" was alone for the same reason, for the longest time, though. Figuring that out was the single hardest part of programming, and why I started favouring flash and interpreted languages. I don't know if the problem is common and well-hidden, or if there's just a subset of the population that has some natural resistance to figuring it out. :P

It's why I still prefer languages like Ruby, that make handling library management and compiling exceptionally easy.

But for C++, the easiest time was definitely as mentioned above - dropping the IDE approach completely, and just compiling on the command line. Hell, the biggest benefits were that, unlike with the IDEs, there are places you can go that will actually explain how command line compiling works and how to do it.

I'll admit that this is probably the biggest reason I hate Eclipse, for example. I'd spend more time trying to figure out compiling than any other thing I did with.
Eclipse is a very bad IDE for anything not Java in my experience.
That said, c++ is a funny language. I have actually only found one IDE which works very well with it. That is visual studio 2010 (Stay away from the 2012 version). Using libraries is easy once you get into the whole adding directories thing.
But honestly the biggest reason to use VS2010 is for debugging. I do not know if you have ever worked with very big projects. I am talking millions of lines of company code here. Debugging in VS2010 is easy, and you can scope directly into into datastructures, variables and even directly into raw memory to see where things are going wrong, and the profiling tools makes finding performance bottlenecks easier than ever. That said, you are right, most IDEs for coding C++ simply suck.

I agree with this post completely. Hence why I said command-line compiling for small projects. For large projects, unless you are some sort of savant and can hold the entire project structure in your head at once (in which case you should be making more money than everybody else combined), an IDE is absolutely necessary. Thankfully, I haven't gotten to that level of work yet.

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #3273 on: October 28, 2012, 03:45:22 pm »

...I like Eclipse for C++. So far I've not found an IDE for Windows with better Autocomplete outside of Visual Studio, and VS doesn't support things like Variadic Templates. Of course it's definitely not great for compiling...

Though maybe if I could get Code-Lite to run instead of just instantly closing...
Logged

GlyphGryph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3274 on: October 28, 2012, 04:07:34 pm »

I agree with this post completely. Hence why I said command-line compiling for small projects. For large projects, unless you are some sort of savant and can hold the entire project structure in your head at once (in which case you should be making more money than everybody else combined), an IDE is absolutely necessary. Thankfully, I haven't gotten to that level of work yet.

Got to be honest, I'm not seeeing it - why is the IDE required? What does it add? Would you only want one for certain classes of languages?

In my experience, the larger the project the more cumbersome they get. If you're programming well, you shouldn't need to keep the whole programming structure in your head just to run a makefile... o_O
Logged

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #3275 on: October 28, 2012, 04:12:23 pm »

What do IDEs add? Autocomplete and Refactoring functionality.

The amount of time saved by not having to flick through documentation or correcting typos due to misspelling a function name, or just not having to type a complete function name because the first three letters are enough is a godsend. And then there's IDEs that let you break sections of code into new functions in a couple of clicks, inline member variables that are just used in one function, extract variables in functions to member variables...

It's great when you don't have to dread the refactor, allowing it to claim it's rightful place as one of the most important steps when programming. You code faster and produce cleaner code, when your tools let you do these things.

I go for a comment-light approach, namely if it's not incredibly complex bit-manipulation or similar (assembly or talking between devices, anything that low level) and it needs comments to be understood, you're doing it wrong. As such things that let me refactor (to split large sections of code into functions with long and descriptive function names) and that let me quickly and easily use long and descriptive variable and function names are very useful.

And if you're doing any kind of TDD these things are vital.
« Last Edit: October 28, 2012, 04:21:29 pm by MorleyDev »
Logged

GlyphGryph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3276 on: October 28, 2012, 05:57:53 pm »

Just wanted to share what I've been working on. You guys may remember a while back, when I asked what language my next project should be in, and a bunch of you said I should clearly build the whole thing in javascript.

Oh, how I laughed, before heading off into C++ land.

However, earlier this week, I began rethinking it, and... Behold!

http://www.test.glyphgryph.com/main.html

Still quite a bit to do there. This is only part 1.
Most of the time it took building it was because the map is dynamically constructed from a json file.

I can't believe this took me half a week for something so simple. But I learned quite a bit about javascript in the process, and I think I've got a really strong skeleton to build on there.
« Last Edit: October 28, 2012, 06:02:58 pm by GlyphGryph »
Logged

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: if self.isCoder(): post() #Programming Thread
« Reply #3277 on: October 28, 2012, 07:18:46 pm »

Sorry for the double post, but actual question this time.

I have

function SomeObject(){
  this.blah = 1;
  this.bloo = myFunc();

  function myFunct(){
    return this.blah+1;
  }
}


This... doesn't seem to work. Javascript scope is hard. :( What do I actually need to do to refer to "blah" in this situation, within the function?
I see a couple of issues. you are attempting to set bloo to be the value returned by myFunc. And myFunc isn't defined yet, so it can't be called. And that probably isn't what you were looking to do anyway.

So we remove the function call syntax and it magically works.
Why does it work? Magic. If myFunct wasn't a function, it would not work.

Code: [Select]
<html>
<head>
<title>JS prototype object oriented programming.</title>
<script type="text/javascript">

function SomeObject(){
  this.blah = 1;
  //this attempts to call myFunc and assign the results to this.bloo
  //that most likely isn't intended
  this.bloo = myFunct();

  function myFunct(){
    return this.blah+1;
  }
}

function SomeObject1(){
  this.blah = 1;
  //this attempts to assign myFunc to bloo
  //but myFunc is not defined when we do this.
  //this results in the enigmatic error "derp.bloo is not a function"
  //this is because myFunct is undefined when you reference it.
  this.bloo = this.myFunct;

  var myFunct = function() {
return this.blah+1;
  };
}

function SomeObject2(){
  this.blah = 1;
  //this attempts to assign myFunc to bloo
  //this works. But how? Magic.
  //javascript has a 2 pass parser that grabs function definitions from the code before attempting to execute it.
  this.bloo = myFunct;

  function myFunct(){
    return this.blah+1;
  }
}

function a() {
var derp = new SomeObject();
alert(derp.bloo());
}
function b() {
var derp = new SomeObject1();
alert(derp.bloo);
}
function c() {
var derp = new SomeObject2();
alert(derp.bloo());
alert(derp.myFunct());
}
</script>
</head>
<body>
<ol>
<li><button onclick="a(); return false;">original</button></li>
<li><button onclick="b(); return false;">don't work either</button></li>
<li><button onclick="c(); return false;">does work</button></li>
</ol>
</body>
</html>
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 #3278 on: October 28, 2012, 07:45:05 pm »

I was actually trying to assign the result of myfunc, rather than the function itself - build up a bunch of defaults, but they shouldn't stay coupled with the initial values, basically.

I ended up working around it, but I still don't quite understand it. For example:
Code: [Select]
function Something(row_height){
  this.starting_row = 1;
  this.current_y_coordinate = moo();
  function moo(){
    return this.starting_row * row_height;
  }
}

However, this doesn't work - "this.starting_row" is undefined in the function, even though the assignment clearly comes before the function is called. I'm not sure exactly what's going on there, and I don't think your examples address it.
Logged

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: if self.isCoder(): post() #Programming Thread
« Reply #3279 on: October 28, 2012, 08:56:36 pm »

I was actually trying to assign the result of myfunc, rather than the function itself - build up a bunch of defaults, but they shouldn't stay coupled with the initial values, basically.

I ended up working around it, but I still don't quite understand it. For example:
Code: [Select]
function Something(row_height){
  this.starting_row = 1;
  this.current_y_coordinate = moo();
  function moo(){
    return this.starting_row * row_height;
  }
}

However, this doesn't work - "this.starting_row" is undefined in the function, even though the assignment clearly comes before the function is called. I'm not sure exactly what's going on there, and I don't think your examples address it.


Building up initial values like that doesn't make a lot of sense unless those were vastly oversimplified examples. why not do something like this?
Code: [Select]
function Something(row_height){
  var that = this;
  this.starting_row = 1;
  this.current_y_coordinate = this.starting_row * row_height;
 
}

But analyzing your current codeblock... "this" references the object that a method belongs too. For an dom event action, this refers to the dom object. For a constructor called with the new keyword, this refers to the object being created. For every other context it refers to the the root object of your execution environment. For browsers, this is the window.

This is a the normal way around that little problem:
Code: [Select]
function Something(row_height){
  var that = this;
  this.starting_row = 1;
  this.current_y_coordinate = moo();
 
  function moo(){
    return that.starting_row * row_height;
  }
}

This is some code that has a snippet that takes a look at what this is inside moo().

Code: [Select]
<html>
<head>
<title>JS prototype object oriented programming.</title>
<script type="text/javascript">


function Something(row_height){
  var that = this;
  this.starting_row = 1;
  this.current_y_coordinate = moo();
 
  function moo(){
var s = "this is["
for (x in this){
s += (x + ": " + this[x]);
}
s += "]";
alert(s);
 
    return that.starting_row * row_height;
  }
}

function a() {
var s = new Something(5);
alert (s.current_y_coordinate);
}
</script>
</head>
<body>
<ol>
<li><button onclick="a(); return false;">fun</button></li>
</ol>
</body>
</html>

yea. I probably should have written another 2 or 8 js tutorials before I fully explained the crapsackitude of the language.
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 #3280 on: October 28, 2012, 09:26:46 pm »

those were vastly oversimplified examples
Yes. :P Obviously. I also just ended up passing all the variables as arguments, but it's nice to know exactly what happened to.

You say:
Quote
For a constructor called with the new keyword, this refers to the object being created. For every other context it refers to the the root object of your execution environment. For browsers, this is the window.
But doesn't this also refer to the object when executing it's prototype's functions?

The that=this trick is pretty cool, though, nice to know.

Also, I know it's still pretty damn basic, but a word or two of encouragement or criticism or even a meh for my "moving a sprite around on a map" javascript thing would be appreciated. :P
Logged

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: if self.isCoder(): post() #Programming Thread
« Reply #3281 on: October 28, 2012, 09:38:14 pm »

wooo! sprite on a map!    ;)

i would have to double check, but in a prototype method, this should refer to the prototyope object.
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.

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3282 on: October 29, 2012, 03:35:57 am »

Behold!

http://www.test.glyphgryph.com/main.html
Whoohoo!  :D I've spent a few weeks in C++ on a "new" project now, and still have less to show :)

Doing it in js will make your game ultra-portable as well, btw. Keep us posted!
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))

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #3283 on: October 29, 2012, 03:51:29 am »

I have a problem I want to solve.

Soil composition is decided by three elements, clay, silt, and sand. There is a ternary plot for it:

Spoiler: large image (click to show/hide)

If I wanted to be able to access this data from a program, I suppose I'll have to create a new version of it in bitmap format that has simple colors for each soil type. Then, I'd use the formula **, multiplied by the correct value, since the formula assumes each side of the triangle has a length of 1, and then find the pixel at that point and figure out the soil type.

...Is there an easier way? Dx I'll have to learn how to access bitmap images at a point, probably through another library, and I have to admit I'm terrible at learning how to use libraries from the documentation.

Also, does SDL or libtcod happen to have the ability to read a bitmap image pixel at (x, y)?

Edit: C++.
« Last Edit: October 29, 2012, 03:57:19 am by Skyrunner »
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

RulerOfNothing

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3284 on: October 29, 2012, 04:07:56 am »

With SDL, you can access the pixel data of any surface (including ones made by SDL_LoadBMP) using the pixels member of the SDL_Surface struct. My copy of the SDL documentation gives this:
Code: [Select]
Uint32 getpixel(SDL_Surface *surface, int x, int y)
{
    int bpp = surface->format->BytesPerPixel;
    /* Here p is the address to the pixel we want to retrieve */
    Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp;

    switch(bpp) {
    case 1:
        return *p;

    case 2:
        return *(Uint16 *)p;

    case 3:
        if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
            return p[0] << 16 | p[1] << 8 | p[2];
        else
            return p[0] | p[1] << 8 | p[2] << 16;

    case 4:
        return *(Uint32 *)p;

    default:
        return 0;       /* shouldn't happen, but avoids warnings */
    }
}
as a general purpose way of extracting the actual pixel data of a SDL surface. I do not know of any simpler ways of doing it (getting the soil type from the composition) unfortunately
Logged
Pages: 1 ... 217 218 [219] 220 221 ... 796