Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

code review

Name: Anonymous 2012-11-04 0:07

i'm new to programming, would anyone mind giving this basic game a review?  it's pretty minimal, but i'd like to know if there are obvious places i can improve now

http://pastie.org/5179576

Name: Anonymous 2012-11-04 0:24

Sure looks like Ruby, alright.

Name: Anonymous 2012-11-04 0:41

Don't use getters and setters in Ruby. Java is pretty much the only language where they're ever needed.
Also, instead of string concatenation and explicit calls to .to_s all the time I'd use string interpolation more (i.e. puts "Player took " + (@playerStartingHealth.to_i - @player.getCurrentHealth.to_i).to_s + " damage." simplifies to puts "Player took #{@playerStartingHealth - player.getCurrentHealth} damage." (why are you using .to_i on integers?)), but that's mostly just a matter of taste.

Name: Anonymous 2012-11-04 0:52

What should I use in place of getters setters?  That seems like the easiest way to do that as far as i'm aware.

Name: Anonymous 2012-11-04 0:55

>>4
attr_accessor. You're already using it for a few variables; use it for everything.

Name: Anonymous 2012-11-04 0:57

Oh, I thought you could only use it for the variables in initialize.  That's awesome.

Name: Anonymous 2012-11-04 4:39

MOTER FUAK

Name: Anonymous 2012-11-04 7:02

>>3
For a moment I thought it was written in ``in Lisp''.

Name: Anonymous 2012-11-04 13:14

drop the camelCase for method names and variables and use setters like so


def player_value=(val)
  @player_value = val
end

Name: Anonymous 2012-11-04 14:14

>>9
What do Rubyists do when they get_really_long_method_names? The usual Cee programmer cop out is to abbreviate in some random fashion (get_rlmnames).

Name: Anonymous 2012-11-04 14:27

>>10
Why would you get long method names in the first place?

Name: Anonymous 2012-11-04 14:46

>>11
When you have a function do_a_thing_then_do_another_thing, that, descriptively enough, does two things in a row, duh.

Name: Anonymous 2012-11-04 15:53

>>10
Maybe this is just taste - things like player_starting_health strike me as being somewhat long, and I absolutely wouldn't tolerate them being even one word longer.

>>12
Well that's kind of a bad example - if you can identify that the function is doing two different things, you should just break it up into two functions that do one thing each.

Name: Anonymous 2012-11-04 16:16

>>13
Okay, how about frobnicate_the_doolally_unless_i_find_my_anus_is_foobar
Description: The function checks its anus (something the caller can't do, since it's a private thing), and if it isn't foobar, then it frobnicates the doolally.

Name: Anonymous 2012-11-04 16:20

>>14
frbnct_dllly_if_anus_not_foobar

Name: Anonymous 2012-11-04 16:25

>>14
You're very bad at constructing abstractions. The Sussman must be turning over in his grave.

Name: Anonymous 2012-11-04 16:28

>>15
That's the cop-out C way
>>16
Thank you!

Name: Anonymous 2012-11-04 19:37

>>15
frbnct s nt sppsd t b rdbl, s sh?

Name: Anonymous 2012-11-04 20:55

>>14
Wouldn't that just turn into frobnicate if you did it right?

Name: Anonymous 2012-11-04 21:34

>>14
Bogus - why not just do this (warning, I don't really know Ruby):


unless e.is_anus_foobar
    e.frobnicate_doolally
end


If you're really worried about exposing the state of anus, you shouldn't even be putting it in the method name. In that case just do as >>19 suggests:


def frobnicate_doolally
    if self.is_anus_foobar
        # freak out
    end
   
    # else, really do something
end

Name: Anonymous 2012-11-19 15:24

>>22
Nice dubs, bro!

Name: Anonymous 2012-11-19 15:49


╔═════════════════ ೋღ☃ღೋ ════════════════╗
~ ~ ~ ~ ~ ~ ~ ~ ~ Repost this if ~ ~ ~ ~ ~ ~ ~ ~ ~
~ ~ ~ ~ you are a strong young black man ~ ~ ~
~ ~ ~ ~ ~ ~ ~ who don’t need no job ~ ~ ~ ~ ~ ~ ~
╚═════════════════ ೋღ☃ღೋ ════════════════╝

Name: Anonymous 2012-11-19 15:53


╔═════════════════ ೋღ☃ღೋ ════════════════╗
~ ~ ~ ~ ~ ~ ~ ~ ~ Repost this if ~ ~ ~ ~ ~ ~  ~
~ ~ ~ ~ you are a strong nigger pedophile ~ ~ ~
~ ~ ~ ~ ~ ~ ~ who don’t need no encryption ~  ~
╚═════════════════ ೋღ☃ღೋ ════════════════╝

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List