views:

121

answers:

7

Java doesn't. (It's just convention)

Delphi does. I believe C# does.

What other languages do?

Edit: I should have given an example:

Delphi: (beware, it's been a while, I may get this wrong)

 type
   TSomething = class
   fEmployeeNum: String;
    property employeeNum: String read fEmployeeNum write setEmployeeNum;
   end;

 procedure TSomething.setEmployeeNum(var val: String);
 begin
   fEmployeeNum := val;
 end;
+1  A: 

VB.NET does through the Property keyword.

Scott Anderson
+1  A: 

C++ doesn't under the standard, but you can create the capacity through templates.

Jekke
+3  A: 

C# does (just to provide an example):

class Foo
{
    public string Bar { get; private set; }
    public string Bargain
    {
        get { return this._Bargain; }
        set { this._Bargain = value; }
    }
    private string _Bargain;
}
Colin Burnett
+1 for giving examples of both the conventional way and Auto Properties.
Alexander Kahoun
+3  A: 

Ruby does through attr_reader, attr_writer, and attr_accessor (for read/write):

class SomeClass
  attr_reader :foo #read-only
  attr_writer :bar #write-only
  attr_accessor :baz #read and write

  ...
end
Pesto
Can you provide a simple example?
Colin Burnett
class X ; attr_reader :foo, def initialize(foo) ; @foo = foo ; end ; end ; X.new('ape').foo #=> 'ape'
rampion
Thanks rampion, but I was hoping for a nicely formatted one like the others here. By all means post it as your own answer and I'll vote it up.
Colin Burnett
This whole thing ought to be CW anyway, but I'll add an example.
Pesto
It is community wiki, unless "CW" means something else.
Colin Burnett
+3  A: 

Python does.

class SomeClass( object ):
def f_get( self ):
    return self.value
fprop = property( f_get )

Code for setter is similar.

S.Lott
Actually, this was the inspiration for the question.
altCognito
A: 

objective c and you can be lazy with the synthesize keyword.

Nick
A: 

In Perl 6,

use v6;

sub foo() is rw {
    state $foo;
    return new Proxy:
        FETCH => method { return $foo },
        STORE => method($to) { $foo = $to };
}

foo = "Hello, world!";
say foo;

...at least in theory. Doesn't seem to work with Rakudo r38250.

ephemient