Skip to main content
Tweeted twitter.com/StackProgrammer/status/754184979656085504

I have recently encountered a class which provides pretty much every single-character as a constant,constant; everything from COMMA to BRACKET_OPEN. Wondering whether this was necessary,necessary; I read an "article" which suggests that it may be helpful to pull single-character literals into constants. So, I'm skeptical...

The main appeal of using constants is they minimize maintenance when a change is needed. But when are we going to start using a different symbol than ',' to represent a comma?

The only reason I see for using constants instead of literals is to make the code more readable. But is city + CharacterClass.COMMA + state (for example) really more readable than city + ',' + state?

For me the cons outweigh the pros, mainly that you introduce another class and another import. And I believe in less code where possible. So, I'm wondering what the general consensus is here.

I have recently encountered a class which provides pretty much every single-character as a constant, everything from COMMA to BRACKET_OPEN. Wondering whether this was necessary, I read an "article" which suggests that it may be helpful to pull single-character literals into constants. So I'm skeptical...

The main appeal of using constants is they minimize maintenance when a change is needed. But when are we going to start using a different symbol than ',' to represent a comma?

The only reason I see for using constants instead of literals is to make the code more readable. But is city + CharacterClass.COMMA + state (for example) really more readable than city + ',' + state?

For me the cons outweigh the pros, mainly that you introduce another class and another import. And I believe in less code where possible. So I'm wondering what the general consensus is here.

I recently encountered a class which provides pretty much every single-character as a constant; everything from COMMA to BRACKET_OPEN. Wondering whether this was necessary; I read an "article" which suggests that it may be helpful to pull single-character literals into constants. So, I'm skeptical.

The main appeal of using constants is they minimize maintenance when a change is needed. But when are we going to start using a different symbol than ',' to represent a comma?

The only reason I see for using constants instead of literals is to make the code more readable. But is city + CharacterClass.COMMA + state (for example) really more readable than city + ',' + state?

For me the cons outweigh the pros, mainly that you introduce another class and another import. And I believe in less code where possible. So, I'm wondering what the general consensus is here.

Question Protected by gnat

I have recently encountered a class which provides pretty much every single-character as a constant, everything from COMMA to BRACKET_OPEN. Wondering whether this was necessary, I read an "article" which suggests that it may be helpful to pull single-character literals into constants. So I'm skeptical...

The main appeal of using constants is they minimize maintenance when a change is needed. But when are we going to start using a different symbol than ',' to represent a comma?

The only reason I see for using constants instead of literals is to make the code more readable. But is city + CharacterClass.COMMA + state (for example) really more readable than city + ',' + state?

For me the cons outweigh the pros, mainly that you introduce another class and another import. And I believe in less code where possible. So I'm wondering what the general consensus is here. Thanks!

I have recently encountered a class which provides pretty much every single-character as a constant, everything from COMMA to BRACKET_OPEN. Wondering whether this was necessary, I read an "article" which suggests that it may be helpful to pull single-character literals into constants. So I'm skeptical...

The main appeal of using constants is they minimize maintenance when a change is needed. But when are we going to start using a different symbol than ',' to represent a comma?

The only reason I see for using constants instead of literals is to make the code more readable. But is city + CharacterClass.COMMA + state (for example) really more readable than city + ',' + state?

For me the cons outweigh the pros, mainly that you introduce another class and another import. And I believe in less code where possible. So I'm wondering what the general consensus is here. Thanks!

I have recently encountered a class which provides pretty much every single-character as a constant, everything from COMMA to BRACKET_OPEN. Wondering whether this was necessary, I read an "article" which suggests that it may be helpful to pull single-character literals into constants. So I'm skeptical...

The main appeal of using constants is they minimize maintenance when a change is needed. But when are we going to start using a different symbol than ',' to represent a comma?

The only reason I see for using constants instead of literals is to make the code more readable. But is city + CharacterClass.COMMA + state (for example) really more readable than city + ',' + state?

For me the cons outweigh the pros, mainly that you introduce another class and another import. And I believe in less code where possible. So I'm wondering what the general consensus is here.

Source Link
Austin Day
  • 1.4k
  • 2
  • 8
  • 9

Are single-character constants better than literals?

I have recently encountered a class which provides pretty much every single-character as a constant, everything from COMMA to BRACKET_OPEN. Wondering whether this was necessary, I read an "article" which suggests that it may be helpful to pull single-character literals into constants. So I'm skeptical...

The main appeal of using constants is they minimize maintenance when a change is needed. But when are we going to start using a different symbol than ',' to represent a comma?

The only reason I see for using constants instead of literals is to make the code more readable. But is city + CharacterClass.COMMA + state (for example) really more readable than city + ',' + state?

For me the cons outweigh the pros, mainly that you introduce another class and another import. And I believe in less code where possible. So I'm wondering what the general consensus is here. Thanks!