• Post Reply Bookmark Topic Watch Topic
  • New Topic

Placement of initialization code  RSS feed

 
Leslie Chaim
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am writing this parsing class and I would like your opinions on where I should place my regex patterns:
list of choices:
  • In the getChunk() method
  • In the Parser constructor
  • In a static initialization block
  • Just a static variable


  • The point is that the regex itself (and the Pattern instance) is hard-coded and never changes. It does not feel right do go with option A.
    Thanks in advance,
    Leslie
     
    Michael Morris
    Ranch Hand
    Posts: 3451
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    If it's hard coded, I'd go with either C or D. D would probably be my first choice.
     
    Leslie Chaim
    Ranch Hand
    Posts: 336
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks Michael for the quick reply,
    Then Case D is:

    I guess then it should also be final.
     
    Michael Morris
    Ranch Hand
    Posts: 3451
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I guess then it should also be final.
    Probably, and you might want to change the name to PARSE_ACTION_LINE to indicate that it is a constant unless you follow some other code convention.
     
    Leslie Chaim
    Ranch Hand
    Posts: 336
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    unless you follow some other code convention.
    No, I am not looking to
    ReinventTheWorld
    or
    REINVENTTHEWORLD
    or
    REINVENT_THE_WORLD
    Standards work perfectly for me , which is exactly why I replied.
    Thanks for your input M&M.
    Later,
    Leslie
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!