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

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

34 active golfers, 116 entries

Solutions by @rmarvie:
56
#15 - r. / @rmarvie

12/19/2014 at 08:17AM

62
#>23 - r. / @rmarvie

12/19/2014 at 08:06AM