Some days ago, with my team we had to fix intern's code.
We found this attempt of hiding hardcode:
return '<span>' + String(34) + '</span>'
That inspired us to figure out some other elegant techniques to hide hardcode:
# Not hard-coded for good practice.
i = 3
return i
# Not hardcoded because its evaluated
i = 6
return i*2 - i
class Result(object):
def __init__(self, value):
self.value = value
def __str__(self):
return str(self.value)
def get_result():
# Object-oriented for good design.
return str(Result(3))
values = ['asd', '3f6s', 'not_hard_coded', 'abfa_efb', 'e2iwwmw']
return [x for x in values if x == 'not_hard_coded'][0]
# Return 32, no one will notice
return ord(' ')
Submit yours
[–]reciam 7ポイント8ポイント9ポイント (1子コメント)
[–]tj-horner 2ポイント3ポイント4ポイント (0子コメント)
[–]AlphaWhelp 5ポイント6ポイント7ポイント (4子コメント)
[–]tj-horner 1ポイント2ポイント3ポイント (3子コメント)
[–]xkcd_transcriber 2ポイント3ポイント4ポイント (2子コメント)
[–]tj-horner 0ポイント1ポイント2ポイント (1子コメント)
[–]xkcd_transcriber 2ポイント3ポイント4ポイント (0子コメント)
[–]rlopezcc 4ポイント5ポイント6ポイント (0子コメント)
[–]BallpointSword 2ポイント3ポイント4ポイント (0子コメント)
[–]netheril96 0ポイント1ポイント2ポイント (0子コメント)
[–]Sadale- 0ポイント1ポイント2ポイント (0子コメント)
[–]I_RATE_YOUR_BEWBS 0ポイント1ポイント2ポイント (2子コメント)
[–]caagr98 2ポイント3ポイント4ポイント (1子コメント)
[–]xkcd_transcriber 1ポイント2ポイント3ポイント (0子コメント)