Poor man's comments.
If 1 = 0 ThenIs nameString empty?
...
End If
if (nameString + "x" != "x") {
...
}Hmm, is the comment wrong, or the code?// Comma-separated list of numbers
string configurationIds = "254:762:2:236:23:5:21";
If 1 = 0 ThenIs nameString empty?
...
End If
if (nameString + "x" != "x") {
...
}Hmm, is the comment wrong, or the code?// Comma-separated list of numbers
string configurationIds = "254:762:2:236:23:5:21";
package tests
import junit.framework._
import org.junit.Assert._
class FirstTest extends TestCase {
override def setUp() = {
}
override def tearDown() = {
}
def testOne() = {
assertEquals(1, 1)
}
}
trait Jumpable {
def jump() : Unit { print("Jumping!") }
}
class Bunny extends Jumpable { ... }
class PogoStick extends Jumpable { ... }
class Controller {
def makeThemJump(jumpers: List[Jumpable]) = {
jumpers.foreach { jumper =>
jumper.jump()
}
}
}Using structural types:class Bunny { def jump(): Unit { print("Jumping!") } }
class PogoStick { def jump(): Unit { print("Jumping!") } }
class Controller {
def makeThemJump(jumpers: List[{ def jump(): Unit }]) = {
jumpers.foreach { jumper =>
jumper.jump()
}
}
}The Twitter guys pointed out that it might be a good idea to avoid structural types due to their use of reflection, which may be slow.class Sock
attr_accessor :colors
def initialize
@colors = [:teal, :olive, :green, :blue, :purple]
end
def machine_washable?
true
end
end
require "sock"
describe "Socks that Kevin would like" do
before :each do
@sock = Sock.new
end
it "should not have pink in it" do
@sock.colors.include?(:pink).should_not == true
end
it "should not have purple in it" do
@sock.colors.include?(:purple).should_not == true
end
it "should be machine washable" do
@sock.should be_machine_washable
end
it "should not have grey in it" do
@sock.colors.include?(:grey).should_not == true
end
it "should have multiple colors" do
@sock.colors.length.should > 1
end
end