Real Vim ninjas count every keystroke - do you?

Pick a challenge, fire up Vim, and show us what you got.

Changelog, Rules & FAQ, updates: @vimgolf, RSS.

Your VimGolf key: please sign in

$ gem install vimgolf
$ vimgolf setup
$ vimgolf put 5491377167afde00024ba4cf

Refactoring useless Method away

Real-life challenge, convert a bunch of ifs to a switch statement

Start file
if (isTyp(YBD.Typ_GEBAEUDE, currentTyp)) {
	immobilienItem.setGebaeudeNr(currentItem.getGebaeudeNr());
}
if (isTyp(YBD.Typ_OBJEKT, currentTyp)) {
	immobilienItem.setObjektNr(currentItem.getObjektNr());
}
if (isTyp(YBD.Typ_ETAGE, currentTyp)) {
	immobilienItem.setEtageNr(currentItem.getEtageNr());
}
if (isTyp(YBD.Typ_IMMOBILIE, currentTyp)) {
	immobilienItem.setImmobilieNr(currentItem.getImmobilieNr());
}
if (isTyp(YBD.Typ_HAUS, currentTyp)) {
	immobilienItem.setHausNr(currentItem.getHausNr());
}
End file
switch (currentTyp) {
	case YBD.Typ_GEBAEUDE:
		immobilienItem.setGebaeudeNr(currentItem.getGebaeudeNr());
		break;
	case YBD.Typ_OBJEKT:
		immobilienItem.setObjektNr(currentItem.getObjektNr());
		break;
	case YBD.Typ_ETAGE:
		immobilienItem.setEtageNr(currentItem.getEtageNr());
		break;
	case YBD.Typ_IMMOBILIE:
		immobilienItem.setImmobilieNr(currentItem.getImmobilieNr());
		break;
	case YBD.Typ_HAUS:
		immobilienItem.setHausNr(currentItem.getHausNr());
		break;
}

View Diff

1,14c1,16
< if (isTyp(YBD.Typ_GEBAEUDE, currentTyp)) {
< 	immobilienItem.setGebaeudeNr(currentItem.getGebaeudeNr());
< }
< if (isTyp(YBD.Typ_OBJEKT, currentTyp)) {
< 	immobilienItem.setObjektNr(currentItem.getObjektNr());
< }
< if (isTyp(YBD.Typ_ETAGE, currentTyp)) {
< 	immobilienItem.setEtageNr(currentItem.getEtageNr());
< }
< if (isTyp(YBD.Typ_IMMOBILIE, currentTyp)) {
< 	immobilienItem.setImmobilieNr(currentItem.getImmobilieNr());
< }
< if (isTyp(YBD.Typ_HAUS, currentTyp)) {
< 	immobilienItem.setHausNr(currentItem.getHausNr());
---
> switch (currentTyp) {
> 	case YBD.Typ_GEBAEUDE:
> 		immobilienItem.setGebaeudeNr(currentItem.getGebaeudeNr());
> 		break;
> 	case YBD.Typ_OBJEKT:
> 		immobilienItem.setObjektNr(currentItem.getObjektNr());
> 		break;
> 	case YBD.Typ_ETAGE:
> 		immobilienItem.setEtageNr(currentItem.getEtageNr());
> 		break;
> 	case YBD.Typ_IMMOBILIE:
> 		immobilienItem.setImmobilieNr(currentItem.getImmobilieNr());
> 		break;
> 	case YBD.Typ_HAUS:
> 		immobilienItem.setHausNr(currentItem.getHausNr());
> 		break;

Solutions by @dsummersl:

Unlock 4 remaining solutions by signing in and submitting your own entry
Created by: @tannerli

32 active golfers, 91 entries

Solutions by @dsummersl:
56
#14 - Dane Summers / @dsummersl

12/19/2014 at 03:12PM

57
#>14 - Dane Summers / @dsummersl

12/19/2014 at 03:01PM

60
#>16 - Dane Summers / @dsummersl

12/19/2014 at 02:59PM

65
#>22 - Dane Summers / @dsummersl

12/19/2014 at 02:58PM