Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 328001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:27:15+00:00 2026-05-12T09:27:15+00:00

Does this rankle anyone else out there? I would much rather see: block.key(newKey); //

  • 0

Does this rankle anyone else out there? I would much rather see:

 block.key(newKey);  // set the key for this block

and

 testKey = block.key();  // look up the key for this block

than

 block.setKey(newKey); // set the key for this block
 testKey = block.getKey(); // look up the key for this block

First, the “set” and “get” are redundant (and hence add noise reducing the readability). The action (set/get) is defined by the syntax of each statement. I understand the overloading. In fact, using the same exact identifier reinforces that these are the same property of the object. When I read “getKey()” and “setKey()” I may not be so sure.

Second, if “get” and “set” are to be strictly interpreted as setter and getter, then if other semantic associated with setting/getting a value, side effects for example, will be surprising.

I suppose this bias comes from my Smalltalk background, but in a world where polymorphism works just fine, wouldn’t we be better off without the “get” and “set” sprinkled everywhere? Just think of how much more code we could type if we didn’t have to type those three letters over and over again?! (tongue somewhat in cheek)

Anyone out there feel the same way?

  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T09:27:16+00:00Added an answer on May 12, 2026 at 9:27 am

    Prefixing accessors with “get” and mutators with “set” is a practice that varies from language to language, and seems to be mostly prevalent in Java. For example:

    • In Python, you have the concept of properties, and so an accessor might look like obj.foo and a mutator might look like obj.foo = bar (even though methods are called behind the scenes). Similar concepts exist in languages such as Ruby. So in a lot of languages, calls to accessors and mutators look like direct “calls” to instance variables, and you never see anything like “setFoo” or “getFoo”.
    • Languages such as Objective-C discourage the practice of prefixing accessors with “get”, so in Objective-C you’d see calls like [obj foo] and [obj setFoo:bar].

    I never liked the practice of prefixing accessors in Java with “get”, either, but I do see the merit in prefixing mutators with “set”. That said, since the prevailing practice is to prefix with “get”/”set” in Java, I continue the trend in my own code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does this code would work as expected in all browsers? Is there any notes
Does this work well as a Singleton in actionscript? i.e. are there any gotchas
Does this smell? I have a few properties you can only set once. They
Does this facade code look like a good idea, or is there anything inherently
Why does this init method return an object out of scope? Using XCode 4.2,
Does this property return, e.g., www1.domain.com, www2.domain.com, etc. And if there is any exception?
Does this code create any memory leaks? Or is there anything wrong with the
Why does this report 980 on the iPhone 4? I thought it would be
Does this condition: if (x > 1) //some logic else if (y >47) //some
Does this: if key == name and item: mean the same as this: if

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.