Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 208 209 [210] 211 212 ... 796

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

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3135 on: October 18, 2012, 10:05:32 pm »

Why do you have both collatznumber and collatzednumber? collatznumber is read in from standard input, has its value assigned to collatzednumber, and then is never used again. You can combine those two variables into one.

Kept the rest of the post in mind and used it all, but this I was confused about for a bit before I remembered that I wanted to write a program that will do the collatz process on every number up until a number of the user's choosing and, at the end, output the number that took the longest to collatz. Naturally, that would probably require an entirely rewritten program, so the "collatznumber" variable is kind of a zombie :P

Warning kids, don't let your variables eat your brains!

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3136 on: October 18, 2012, 11:29:46 pm »

More from my program:

This is how babby river is made!

Approximately 1 hour of run time which I timelapsed into 2 minutes @ 30fps, with each frame being 1 second.
Logged

MadocComadrin

  • Bay Watcher
  • A mysterious laboratory goblin!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3137 on: October 19, 2012, 01:57:58 am »

What this means is that calling MyCustomCollection.keySet().remove(key) DOES NOT call MyCustomCollection.remove(key)... so any logic you have to perform when removing something from your collection? gets shit on. You have to create an inner class to handle each of these collections f you have special logic that must execute on insert/removal.
Why would you expect anything different? You're removing data from an entirely separate object (which just happens be created by another object). Having the mutation of the set affect the general collection seems dangerous (in general) and inconsistent with Java's general trend to idiot-proof things. My question is, where would you only have access to a set containing the keys where you wouldn't have access to the original collection? Alternatively, why would you need to remove it from the set of keys and have that update the original collection when you could just remove it directly from the collection?
Logged

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: if self.isCoder(): post() #Programming Thread
« Reply #3138 on: October 19, 2012, 07:44:33 am »

why? because that is the contract defined for the various collections interfaces. the keyset and other such collections are supposed to be baacked by the original collection..
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.

MadocComadrin

  • Bay Watcher
  • A mysterious laboratory goblin!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3139 on: October 19, 2012, 08:52:54 am »

Very well, but that caused me to take a second look at that specific contract: it doesn't say it has to call the original collection's remove method; rather, it only has to remove the mapping. I know there are map-based collections in the framework that have to perform logic on removal.

So all in all, the onus would indeed be on you to ensure that the contract is upheld for you specific class, however you chose to do so. Taking a look at the source for a hashMap, an inner class is indeed a solution. 
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #3140 on: October 19, 2012, 08:59:15 am »

Help Dx

In VC 2010, I added the option /ignore:4482 in the command line arguments for compiling. That error is

Quote
warning C4482: nonstandard extension used: enum 'enum_name' used in qualified name

because I stubbornly used regular enums as, for example, KEYS:kUP instead of just kUP in hopes that whenever I get a compiler that works with strongly typed enums that I can just edit the definition of the enum and go.

Well, the compiler spams me with 4482, so I added the option.

And it still spams me. Any help?
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

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3141 on: October 19, 2012, 09:26:35 am »

#pragma warning(disable : 4482)
Those can be used to disable any warning, starting at the code where it is placed.
#pragma warning(default : 4482)
Those will re-enable the warning to act as usual, starting at the code where it is placed. They can be really handy when you get a specific warning set in a specific area of code; though it may be dangerous to not re-enable them afterwards unless you know for a fact that all warnings of that type won't help you in the context of your code.
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #3142 on: October 19, 2012, 09:41:31 am »

Thanks, worked like a charm :D
And I do know that 4482 won't impact me at all even if disabled.

Though I wonder why /ignore:4482 doesn't work as advertised :<
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

dreadmullet

  • Bay Watcher
  • Inadequate Comedian
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3143 on: October 21, 2012, 11:29:27 am »

How do I create a global, constant instance of some class, with edited values? (I hope that makes sense.) For example, I basically want to do this, without the compile errors:

Code: (C++) [Select]
// SomeClass is a class defined elsewhere
SomeClass foo;
foo.x = 42;
foo.name = "Foo's Name";

int main(){
    cout << foo.name;
}

What I want is for foo to be a part of the compiled .exe, kind of like how you can have constant arrays with values filled in them.
Logged

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3144 on: October 21, 2012, 12:25:48 pm »

How do I create a global, constant instance of some class, with edited values? (I hope that makes sense.) For example, I basically want to do this, without the compile errors:

Code: (C++) [Select]
// SomeClass is a class defined elsewhere
SomeClass foo;
foo.x = 42;
foo.name = "Foo's Name";

int main(){
    cout << foo.name;
}

What I want is for foo to be a part of the compiled .exe, kind of like how you can have constant arrays with values filled in them.

There's a couple of different ways to do this. You can make it a static object in the global scope, and initialize the values via the class's constructor. The OOP way would be to have accessor and mutator methods in the class, and make the instance fields private (or at least protected). The super-overkill-OOP way would be to make it a public static field of another class defined in the global scope.

dreadmullet

  • Bay Watcher
  • Inadequate Comedian
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3145 on: October 22, 2012, 02:28:50 am »

So there's no easy way to do it, it seems. Thanks anyway.



I have another library linking problem with CodeBlocks. I absolutely cannot compile anything when I include boost::filesystem, no matter what I try. boost::filesystem requires you to build boost and link the libraries, and I'm almost positive I did it correctly. I made sure I built it for GCC, too.

Here's a simplified program:

Code: (C++) [Select]
#include <boost/filesystem.hpp>

int main(){

return 0;

}

I can get this to compile in Visual Studio, but not CodeBlocks. I get this error when I compile:

Code: [Select]
Linking console executable: bin\Debug\Sandbox.exe
C:\Boost\lib/libboost_system-mgw47-mt-1_49.a(error_code.o):error_code.cpp:(.text+0x120): undefined reference to `_Unwind_Resume'
C:\Boost\lib/libboost_system-mgw47-mt-1_49.a(error_code.o):error_code.cpp:(.text+0x128): undefined reference to `_Unwind_Resume'
C:\Boost\lib/libboost_system-mgw47-mt-1_49.a(error_code.o):error_code.cpp:(.text+0x38d): undefined reference to `_Unwind_Resume'
C:\Boost\lib/libboost_system-mgw47-mt-1_49.a(error_code.o):error_code.cpp:(.eh_frame+0xa3): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status

I kind of doubt anyone has a solution, since Google is no help. Any suggestions would be appreciated.



EDIT: Greetings people in the future googling this problem, I have a solution:

I solved it! All I had to do was define BOOST_SYSTEM_NO_DEPRECATED and it magically worked. Yay for being desperate and trying everything.
« Last Edit: October 22, 2012, 06:31:52 pm by dreadmullet »
Logged

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #3146 on: October 22, 2012, 04:18:09 am »

You aren't linking to one of the boost libraries needed by boost filesystem.

Also global variables in c++ are, as a general rule, bad bad things that you should avoid when possible.
Logged

dreadmullet

  • Bay Watcher
  • Inadequate Comedian
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3147 on: October 22, 2012, 05:03:01 am »

You aren't linking to one of the boost libraries needed by boost filesystem.

According to more than one source, I have to link to boost filesystem and boost system, which I had done, but it didn't work. I just tried linking to every library in the \lib directory, and it still gets the error message. What else would there be to link to?
Logged

Skyrunner

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

Why are they bad, though? I've never really seen an article that goes in-depth, just that they're baaad.
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

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #3149 on: October 22, 2012, 05:21:29 am »

Why are they bad, though? I've never really seen an article that goes in-depth, just that they're baaad.

It automatically introduces a state to code which can change at any time, making code more difficult to predict, test and debug. Also it reduces reusability and makes everything aware of something they have no need to be aware of, meaning they break the strong encapsulation typical of a good design.

Also global variables killed a puppy.
« Last Edit: October 22, 2012, 05:24:37 am by MorleyDev »
Logged
Pages: 1 ... 208 209 [210] 211 212 ... 796