Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 386 387 [388] 389 390 ... 796

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

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #5805 on: May 02, 2014, 07:39:53 am »

Most Software/Computer Science/Computing courses don't teach good design, and I don't think it's easy to truly teach in a classroom setting. It's something best learnt in the field, I find. It's why I think students of anything computer related should always do a placement/internship year as part of their course (unless they've already worked in the industry, but if they've already worked in the industry their entire degree is really just so they can have a degree).

The most effective way is the least efficient when you have a class full of students, since you need for someone to have written something poorly designed and felt the pain of a bad design, and then take that someone and have them work with someone who knows good design and who shows them opinions on the better ways to do it. After all, if you haven't truly felt the pain of a bad design, you'll not truly understand the reasons that make something a good one.

Feel the pain is a common phrase I hear from Agile people, but I can't actually trace an origin for it so I'm not sure how ubiquitous is is. It basically means "Why do we fall? To get back up.", if you don't feel the pain of a bad problem you won't know where to apply fixes to make a good solution.
« Last Edit: May 02, 2014, 07:49:42 am by MorleyDev »
Logged

Lightningfalcon

  • Bay Watcher
  • Target locked. Firing main cannon.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5806 on: May 02, 2014, 07:20:19 pm »

I'm looking at things now. Still working on figuring out how it's supposed to work. Why, oh why, are all of the variables in reader declared at the class level?

I could go on and on with style tips/code review stuff if you're interested.

Will hopefully post again soon with assistance.

EDIT instead of double-post:

In reader's constructor, you're re-using the same ArrayLists over and over. Think about that for a moment before you open the spoiler.

Spoiler: Why is that bad? (click to show/hide)

Spoiler: How to fix? (click to show/hide)
That managed to work perfectly.  Unfortunately my new problem is that the computer I have to present it on is running Java 6, because my teacher apparently had trouble with a piece of software when it updated to 7.  So to get it to run in six do I only have to use the JDK for six?  And if so which would I use?  The Java archive here have everything from 6 to 6u45.  What are the differences between all of these? 
Logged
Interdum feror cupidine partium magnarum circo vincendarum
W-we just... wanted our...
Actually most of the people here explicitly wanted chaos and tragedy. So. Uh.

SolarShado

  • Bay Watcher
  • Psi-Blade => Your Back
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5807 on: May 03, 2014, 02:28:39 am »

To anyone posting large amounts of code:
Please consider using something like pastebin.com or gist.github.com (gist can handle multiple files!), it'll keep your posts cleaner and make the code easier to read.

That managed to work perfectly.  Unfortunately my new problem is that the computer I have to present it on is running Java 6, because my teacher apparently had trouble with a piece of software when it updated to 7.  So to get it to run in six do I only have to use the JDK for six?  And if so which would I use?  The Java archive here have everything from 6 to 6u45.  What are the differences between all of these?

Oh, that's one I've actually never directly dealt with. A quick google finds this StackOverflow post about netbeans (which I've never used). If you're using Eclipse, it's under project properties somewhere (try Java Build Path and Java Compiler; "generated .class files compatibility" in the latter looks promising); I don't have a new version handy on this machine. If you're building manually with javac, the "-target" option looks like what you need.

So, it looks like JDK 7 can build for JRE 6, and you're almost certainly not using any 7-only libraries, so that should be fine. Ideally, test first. If you really want to be sure, you can always uninstall 7 and just use 6 (or try running it on some other computer that only has 6).

As for code review, the first big thing I'd mention is names. Give your variables descriptive names! Unless you're using Notepad(*), your code editor/IDE should autocomplete them, so there's no excuse to not use full words for your variable names. This is doubly important for class and method names. And always capitalize your class names! It's such a firmly entrenched convention, it's disorienting when it is broken.

Second important thing, always declare your variables at the innermost scope possible. Is that string set at the start of each iteration of your loop and never needed outside of it? Declare it inside the loop! If you're careful you can even reuse the same name in different places (with different types!).

I'll get some more detailed stuff put together tomorrow: It's 3:30am here now. Feel free to put up your most recent code.

(*)And if you are using Notepad, stop. Now. Seriously. Go download Notepad++, it's got autocomplete and syntax highlighting and tabbed editing.
Logged
Avid (rabid?) Linux user. Preferred flavor: Arch

Mephisto

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5808 on: May 03, 2014, 06:10:05 am »

To anyone posting large amounts of code:
Please consider using something like pastebin.com or gist.github.com (gist can handle multiple files!), it'll keep your posts cleaner and make the code easier to read.

If you hate having to do anything besides dump text into a textbox, at least don't put your code blocks into spoilers. The minor inconvenience of having to scroll for slightly longer is offset by the ability of others to actually read your code without copy/pasting it elsewhere.
Logged

gigaraptor487

  • Bay Watcher
  • Escaped Lunatic now civilised
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5809 on: May 03, 2014, 05:32:41 pm »

Hello, I have posted a few times on this thread with no real significance to any of them, but I would like some advice from people who have reached this point in the past. I have been programming on and off for 4 years but really started to program seriously about 18 months ago, and now I have knowledge of C, C++, x86 assembler and Python as well as the respective standard libraries(save of course ASM) and NCurses and have successfully written a few dozen programs with C/C++. a few python and one x86 Assembler one(mind you making anything of utility is time consuming with Pure x86 assembler as many will know).

The problem Is that I have no idea what to do next. I am not sure whether to join an open source project or to specialize in some field( the only ones that have really sprung to mind are Game Programming, Compilers and Operating systems considering I am still quite young) or whether to learn Java or not(although saying that I have to learn it anyway next year).

tl;dr : Have learnt a few languages to a usable degree but have no Idea what to do next with my new skills, what algorithms to learn etc.

However from what I have done I have discovered a few things:
- I dislike graphics programming
- I do like more lower level programming (like to make things quick)
- No interest in programming things like browsers (servers are a different story however)
- I enjoy programming into the small hours of the morning.


Can anybody help me with this.


Thanks a million.
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

Gatleos

  • Bay Watcher
  • Mournhold... City of Light... City of MAGIC!
    • View Profile
    • Someone Sig This
Re: if self.isCoder(): post() #Programming Thread
« Reply #5810 on: May 03, 2014, 06:58:03 pm »

You like getting your hands dirty with optimization and dislike graphics programming, huh? I'm sure you could find plenty of open source projects to contribute to. One that springs to mind is OpenRCT2, but that's just because you said you have experience with both x86 assembly and C. Cataclysm: DDA is an open source branch of an ascii-based roguelike that got its start here, they could definitely use some help with optimization and such over there.

Just a few off the top of my head.
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

Lightningfalcon

  • Bay Watcher
  • Target locked. Firing main cannon.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5811 on: May 03, 2014, 07:04:52 pm »

Maybe you could do something like encryption?  I'm pretty sure that optimization could be useful when running really big numbers.   
Logged
Interdum feror cupidine partium magnarum circo vincendarum
W-we just... wanted our...
Actually most of the people here explicitly wanted chaos and tragedy. So. Uh.

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5812 on: May 04, 2014, 03:11:53 am »

Yeah, it sounds to me like encryption might be right up your alley. How's your math background?

da_nang

  • Bay Watcher
  • Argonian Overlord
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5813 on: May 04, 2014, 04:13:12 am »

You could also work on compilers.
Logged
"Deliver yesterday, code today, think tomorrow."
Ceterum censeo Unionem Europaeam esse delendam.
Future supplanter of humanity.

gigaraptor487

  • Bay Watcher
  • Escaped Lunatic now civilised
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5814 on: May 04, 2014, 05:38:22 am »

Thanks for all the help thus far. My math background is quite small (mainly because I haven't done the GCSE yet,although know eveything that it consists of well) but I like it and my grades tend to reflect that. The maths generally consists of this:clicky. Although within programming I have learnt quite a lot of more advanced math out of neccessity and on occasion curiousity(bubble sort, a little calculus, big O notation etc)

However what I find is that a lot of the better textbooks cost a lot more than I actually have and are willing to spent and seldom show up on ebay for what I would consider a decent price, especially the ones on compilers.

I think I will have a look at catalysm dda as I have played it since the first version once I get exams out the way.

Thanks
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

Gatleos

  • Bay Watcher
  • Mournhold... City of Light... City of MAGIC!
    • View Profile
    • Someone Sig This
Re: if self.isCoder(): post() #Programming Thread
« Reply #5815 on: May 04, 2014, 07:14:46 pm »

Ugh, I just finished a program that outputs the fibonacci sequence in MarioLANG. It's like pulling teeth.

...Programming is fun.
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

Vattic

  • Bay Watcher
  • bibo ergo sum
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5816 on: May 04, 2014, 11:32:19 pm »

While messing around with Python by making a simple Conway's Game of Life program I hit a problem where it just wouldn't work. I ended up finding someone else's and comparing. Theirs was different in a number of ways, but mostly the same. Only one line was massively different and by doing the same as them mine started working. I don't understand why and would appreciate some help.

My .py file.

It's line 64 that bugs me. From what I gather it swaps the contents of the two lists. I don't see why it is necessary to set nexGen to the contents of curGen. Originally I was emptying nexGen at the start of each tick. I suspect I'm missing something blatant. Any ideas?

Edit: stripped all the Libtcod stuff out of the wrong version, fixed now.
« Last Edit: May 04, 2014, 11:43:38 pm by Vattic »
Logged
6 out of 7 dwarves aren't Happy.
How To Generate Small Islands

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5817 on: May 05, 2014, 01:01:23 am »

That line does two things:

1. curGen = step(curGen, nexGen)
2. nexGen = curGen

Using Python magic, they happen at "the same time" - it's the same as this:

1. temp = curGen
2. curGen = step(curGen, nexGen)
3. nexGen = curGen

As far as I can tell, step seems to increment the game board using GoL death/birth/life rules. I'm not really sure either why it does that, since nexGen gets filled with 0's during each call to step. Is that your code, or the code you found?

i2amroy

  • Bay Watcher
  • Cats, ruling the world one dwarf at a time
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5818 on: May 05, 2014, 01:11:40 am »

Yeah, from what I see the swap is totally unneeded and could just as easily be done as "curGen = step(curGen, nexGen)". If you are getting a problem from somewhere, I don't think that line would have anything to do with it.
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.

Vattic

  • Bay Watcher
  • bibo ergo sum
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5819 on: May 05, 2014, 01:26:32 am »

That's my code, but the line in question is based on the only major difference between the one I found and mine.

If I replace that line with "curGen = step(curGen, nexGen)" then I get three broken generations before a blank board. The same problem if I start it in a state that should just oscillate.

Oh and if I replace that line with the three you said are equivalent it breaks down in the same way.
Logged
6 out of 7 dwarves aren't Happy.
How To Generate Small Islands
Pages: 1 ... 386 387 [388] 389 390 ... 796