Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 370 371 [372] 373 374 ... 796

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

GlyphGryph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5565 on: March 13, 2014, 03:50:52 pm »

But Ruby is just a better version of python!
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5566 on: March 13, 2014, 04:19:06 pm »

But Ruby is just a better version of python!

With only 500% more incomprehensible syntax! :I

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5567 on: March 14, 2014, 07:42:17 am »

Using the Android emulator?  Good.  Luck.  I hope it's improved by a leap and a bound since the last time I touched it, because if it hasn't you can expect several full minutes each time you have to reboot it.  Depending on how large your application is, it may take a full minute to download and run it too.

I once had to debug a web app we made on several versions of the OS that nobody in the office had a phone with.  That was one of the most maddening experiences in my life.  It took an unbelievably long time because I was often literally waiting on the thing to start or start the app.  Couple that with the fact that older versions of Android had one of the most hilariously glitchy web browsers in recent history, and you've got a recipe for incomprehensible fury.  I honestly can't believe how bad the browser used to be.

Minor nitpick is that Java doesn't have an escape character for line separator independent from the OS. It's either System.getProperty("line.separator"); or cry.

Do many languages use a single escape sequence for ending lines?  I'm almost positive PHP does the same thing through a predefined variable or something.  Even in C++ I believe I've read that std::endl doesn't automatically choose the ending type for the platform being developed for, but if it doesn't I have no idea what it does do.  I'm guessing it's language lawyering and that it's just left up to the compiler, which does implement it in the system appropriate way.

I can see some justification for not always expanding \n into the system appropriate line ending.  What if you're writing something to be output to a browser for example?  I believe most HTTP related things actually mandate CR LF endings.
Logged
Through pain, I find wisdom.

ECrownofFire

  • Bay Watcher
  • Resident Dragoness
    • View Profile
    • ECrownofFire
Re: if self.isCoder(): post() #Programming Thread
« Reply #5568 on: March 14, 2014, 03:41:53 pm »

Do many languages use a single escape sequence for ending lines?  I'm almost positive PHP does the same thing through a predefined variable or something.  Even in C++ I believe I've read that std::endl doesn't automatically choose the ending type for the platform being developed for, but if it doesn't I have no idea what it does do.  I'm guessing it's language lawyering and that it's just left up to the compiler, which does implement it in the system appropriate way.

I can see some justification for not always expanding \n into the system appropriate line ending.  What if you're writing something to be output to a browser for example?  I believe most HTTP related things actually mandate CR LF endings.

In C and C++ "\n" in a string will automatically expand to the appropriate line ending.

std::endl is not only a line ending. It appends a line ending to the stream, yes, but it also flushes the stream.
Logged

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5569 on: March 14, 2014, 04:41:49 pm »

Ah, that makes sense.

Quote
In C and C++ "\n" in a string will automatically expand to the appropriate line ending.

I find it amazing that I didn't know this.  Admittedly, it's been a long time since I've done anything major with raw strings in C or C++, but I could have sworn up and down that I've had problems in the distant past with just using '\n' with written files and Windows software not recognizing the line endings.  Maybe it was just very old versions of Visual Studio?  This is something like 15 years ago (back before I knew how to use C++ streams), so maybe I just can't remember.
Logged
Through pain, I find wisdom.

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5570 on: March 14, 2014, 06:08:00 pm »

Ah, that makes sense.

Quote
In C and C++ "\n" in a string will automatically expand to the appropriate line ending.

I find it amazing that I didn't know this.  Admittedly, it's been a long time since I've done anything major with raw strings in C or C++, but I could have sworn up and down that I've had problems in the distant past with just using '\n' with written files and Windows software not recognizing the line endings.  Maybe it was just very old versions of Visual Studio?  This is something like 15 years ago (back before I knew how to use C++ streams), so maybe I just can't remember.

Honestly, I wouldn't be surprised if VS was lacking that functionality still. However, when it comes to reading in from files, CR/LF is still a gotcha, especially if the document has CR-LFs and you're developing on a Unix/Linux platform, which expects LF. The easiest way I've found to deal with it is thus:

Code: (C++03) [Select]
string str;
getline(stream, str); // str may or may not have a trailing CR
if(*str.end()=='\r') str = str.substr(0, str.length()-1);

And because I love C++11 so much more:

Code: (C++11) [Select]
string str;
getline(stream, str); // str may or may not have a trailing CR
if(str.back()=='\r') str.pop_back();

ECrownofFire

  • Bay Watcher
  • Resident Dragoness
    • View Profile
    • ECrownofFire
Re: if self.isCoder(): post() #Programming Thread
« Reply #5571 on: March 15, 2014, 03:29:56 pm »

Basically when you read a file in on Windows that has CR/LF line endings, they're transformed into \n. But when you output a \n, it's turned into a CR/LF before being written.

This only applies to files opened in "text" mode (which is the default).
Logged

gigaraptor487

  • Bay Watcher
  • Escaped Lunatic now civilised
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5572 on: March 15, 2014, 04:01:42 pm »

A Few Questions:
1) I am mainly a C programmer, but also know HTML/CSS. I have found myself wanting to setup a small website to help show people some of my work(sourceforge is ok but I would rather make use of my spare computers as servers). I have thought about perhaps learning PHP and perhaps Javascript to run said website. What I want to know is it relatively easy to learn them (especially PHP) given that I have practiced C for a few years and have a qualification in HTML/CSS (mind you it was a GCSE).
2) As having programmed C for a while, I have made a number of small projects(never numbering more than half a dozen source and header files) but I would like to produce something of a larger scale. Is there any way in particular to code accommodating for larger amounts and for more complexity?
3) I am quite interested in how games like Audiosurf and Beat Hazard analyse the music to generate there levels. Are there any libraries that you are aware of that do this or theory texts I can read in order to implement one of my own?
4) I wrote this code about 6 months ago, It would be nice to get some pointers to become a better programmer and perhaps contribute to open source projects sometime (I don't think it is an atrocity, especially compared to something like the Lugaru source code).

Thank you all for the assistance.
 
Logged
Hehe, you thought there would be an interesting sig here

I now run a program which brings old multiplayer games back to life : click

Mephisto

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5573 on: March 15, 2014, 04:11:15 pm »

4) I wrote this code about 6 months ago, It would be nice to get some pointers to become a better programmer and perhaps contribute to open source projects sometime (I don't think it is an atrocity, especially compared to something like the Lugaru source code).

I haven't looked at the code yet, but I have a few VCS tips.

Your commit messages are... not good. They're generally for describing what your commit does. Git has a separate way of tagging a given commit as a release.

You shouldn't include derived files. I see you have a makefile. Since running it creates the executable, you don't have to include said exe in the repo.
Logged

gigaraptor487

  • Bay Watcher
  • Escaped Lunatic now civilised
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5574 on: March 15, 2014, 04:38:25 pm »

I see what you mean.
Logged
Hehe, you thought there would be an interesting sig here

I now run a program which brings old multiplayer games back to life : click

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5575 on: March 15, 2014, 11:49:43 pm »

Basically when you read a file in on Windows that has CR/LF line endings, they're transformed into \n. But when you output a \n, it's turned into a CR/LF before being written.

This only applies to files opened in "text" mode (which is the default).

Ah, text mode.  I habitually open files in binary mode, mostly because I read several times to avoid text mode when I was learning to program.  I pretty much never write software that's supposed to run on both Windows and Linux, so the differences haven't really mattered to me.
Logged
Through pain, I find wisdom.

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #5576 on: March 16, 2014, 06:19:13 am »

Fudge. My plant sim manages to run out of memory in a mere ~800 days of simulation, and crashes. The problem is that it's way too easy for plants to grow and reproduce, and I haven;t figured out a reasonable way to kill them off fast enough >_<

Just before it crashed, it used 1978672 KB of memory, which is 1.88 GB.
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

Sheb

  • Bay Watcher
  • You Are An Avatar
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5577 on: March 16, 2014, 06:34:27 am »

Can't you limit the area they grow on?
Logged

Quote from: Paul-Henry Spaak
Europe consists only of small countries, some of which know it and some of which don’t yet.

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #5578 on: March 16, 2014, 06:45:22 am »

It's not the area, but more that like fifty plants seem to start growing on one patch :x
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

Sheb

  • Bay Watcher
  • You Are An Avatar
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5579 on: March 16, 2014, 06:52:05 am »

Do you take competition into account? This should weed out the extra plants quickly.
Logged

Quote from: Paul-Henry Spaak
Europe consists only of small countries, some of which know it and some of which don’t yet.
Pages: 1 ... 370 371 [372] 373 374 ... 796