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 @mnxx:

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

34 active golfers, 116 entries

Solutions by @mnxx:
54
#14 - mnx / @mnxx

12/17/2014 at 11:06AM

55
#>14 - mnx / @mnxx

12/17/2014 at 10:53AM

57
#>16 - mnx / @mnxx

12/17/2014 at 10:51AM

58
#>17 - mnx / @mnxx

12/17/2014 at 10:41AM

59
#>18 - mnx / @mnxx

12/17/2014 at 10:03AM