# What is the use case for delegate?

**URL:** <https://forum.crystal-lang.org/t/what-is-the-use-case-for-delegate/1180>\
**Category:** Help & Support\
**Created:** [September 30, 2019, 4:49am UTC](https://forum.crystal-lang.org/t/what-is-the-use-case-for-delegate/1180 "2019-09-30T04:49:58Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![girng\_github](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/girng_github/32/571_2.png) [@girng\_github](https://forum.crystal-lang.org/u/girng_github)\
**Post date:** [September 30, 2019, 4:49am UTC](https://forum.crystal-lang.org/t/what-is-the-use-case-for-delegate/1180/1 "2019-09-30T04:49:58Z")

</div>

I’m starting to see `delegate` used, and I’m trying to understand its use case.

What is the difference between

```auto
class StringWrapper
  def initialize(@string : String)
  end

  delegate downcase, to: @string
  delegate gsub, to: @string
  delegate empty?, capitalize, to: @string
  delegate :[], to: @string
end

wrapper = StringWrapper.new "HELLO"
wrapper.downcase # => "hello"
wrapper.gsub(/E/, "A") # => "HALLO"
wrapper.empty? # => false
wrapper.capitalize # => "Hello"

```

And:

```auto
wrapper = "HELLO" 
pp wrapper.downcase       
pp wrapper.gsub(/E/, "A")  
pp wrapper.empty?          
pp wrapper.capitalize      

```

Or:

```auto
class String2
  property s : String
  def initialize(@s : String)
  end
end

stringer = String2.new("HELLO")
 
pp stringer.s.downcase       
pp stringer.s.gsub(/E/, "A")  
pp stringer.s.empty?          
pp stringer.s.capitalize

```

From the docs:  
[https://crystal-lang.org/api/master/Object.html#delegate(\*methods,toobject)-macro](https://crystal-lang.org/api/master/Object.html#delegate(*methods,toobject)-macro)

> Delegate _methods_ to _to_ .

Okay? But why? When you can just use string literal syntax `" "` and call the string methods. Or, use a class with a `s` property (String type), that uses the innate `String` methods. If you need a wrapper, the developer can use method overloading (or implement their own methods!) on their class, which follows OOP design.

What am I missing here?

---

<div class="post-metadata">

**Author:** ![Blacksmoke16](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/blacksmoke16/32/1241_2.png) [@Blacksmoke16](https://forum.crystal-lang.org/u/Blacksmoke16)\
**Post date:** [September 30, 2019, 5:06am UTC](https://forum.crystal-lang.org/t/what-is-the-use-case-for-delegate/1180/2 "2019-09-30T05:06:53Z")

</div>

The main use case is allowing the user to use some methods on an internal ivar within a class, without exposing the actual ivar to the user.

Example

```auto
class Validator
  def valid?(value : String)
    value == "foo"
  end
end

class WithoutDelegate
  getter validator : Validator = Validator.new
end

# Notice in this case you have to make a getter
# to the validator class
pp WithoutDelegate.new.validator.valid? "foo"

class WithDelegate
  delegate :valid?, to: @validator
  
  @validator : Validator = Validator.new
end

# Notice in this case we can keep the validator
# instance private and just expose a select few 
# methods on it. Also notice the UX is nicer
# since you dont have to have that extra
# .validator in there
pp WithDelegate.new.valid? "foo"

```

In the example you provided they’re similar, but the `StringWrapper` is only allowing a subset of `String`'s methods to be used. If you tried to do `wrapper.tr("l","")` it wouldn’t compile since `StringWrapper` doesn’t have a `tr` method defined, and you’re not delegating it to the internal string.

---

<div class="post-metadata">

**Author:** ![girng\_github](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/girng_github/32/571_2.png) [@girng\_github](https://forum.crystal-lang.org/u/girng_github)\
**Post date:** [September 30, 2019, 5:18am UTC](https://forum.crystal-lang.org/t/what-is-the-use-case-for-delegate/1180/3 "2019-09-30T05:18:50Z")

</div>

> [@Blacksmoke16](#):
>
> The main use case is allowing the user to use some methods on an internal ivar within a class, without exposing the actual ivar to the user.

Wait, I thought the entire point of an ivar is so it can be used by a class? Why would a developer not want it to be “exposed”?

> In the example you provided they’re similar, but the `StringWrapper` is only allowing a subset of `String` 's methods to be used

Isn’t this a negative though? Why limit the potential methods of a base type (String) to a developer? So, if that developer needed to call an innate String method, they would now… have to add a delegate method, before being able to use the method that the `String` type already offers? Wtf

IMHO, this adds another layer of anti-brevity, and another layer of complexity that can already be done with a `class`. More importantly, **yet another keyword** , a new developer has to understand and process while reading code.

---

<div class="post-metadata">

**Author:** ![Blacksmoke16](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/blacksmoke16/32/1241_2.png) [@Blacksmoke16](https://forum.crystal-lang.org/u/Blacksmoke16)\
**Post date:** [September 30, 2019, 5:27am UTC](https://forum.crystal-lang.org/t/what-is-the-use-case-for-delegate/1180/4 "2019-09-30T05:27:04Z")

</div>

> [@girng\_github](#):
>
> Wait, I thought the entire point of an ivar is so it can be used by a class? Why would a developer not want it to be “exposed”?

It’s perfectly fine to have an ivar be used internally by the class but not exposed to the user, i.e. one that doesn’t have a getter method.

> [@girng\_github](#):
>
> Isn’t this a negative though? Why limit the potential methods of a base type (String) to a developer? So, if that developer needed to call a innate String method, they would now… have to add a delegate method, before being able to use the method that the `String` type already offers?

That example was just showing how delegate works, this isn’t specific to strings.

In the end `delegate` is just a macro that defines a new method to make writing like

```auto
class WithDelegate 
  @validator : Validator = Validator.new

  def valid?(value : String)
    @validator.valid? value
  end
end

```

a bit easier, as that’s exactly what it does. It’s just a macro to reduce boilerplate, like `getter` or `property`.

---

<div class="post-metadata">

**Author:** ![girng\_github](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/girng_github/32/571_2.png) [@girng\_github](https://forum.crystal-lang.org/u/girng_github)\
**Post date:** [September 30, 2019, 5:30am UTC](https://forum.crystal-lang.org/t/what-is-the-use-case-for-delegate/1180/5 "2019-09-30T05:30:50Z")

</div>

> [@Blacksmoke16](#):
>
> That example was just showing how delegate works, this isn’t specific to strings.

That’s even worse though, because now the developer has to add a `delegate` to any type they delegated, **just to use an innate METHOD that already exists for that typ** e. That’s an unnecessary step and is objectively a negative.

> [@Blacksmoke16](#):
>
> It’s perfectly fine to have an ivar be used internally by the class but not exposed to the user, i.e. one that doesn’t have a getter method.

That would be a local variable, not an ivar? An instanced variable is… a property of a class. It should be freely accessed, no? If not, why?

---

<div class="post-metadata">

**Author:** ![Blacksmoke16](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/blacksmoke16/32/1241_2.png) [@Blacksmoke16](https://forum.crystal-lang.org/u/Blacksmoke16)\
**Post date:** [September 30, 2019, 5:38am UTC](https://forum.crystal-lang.org/t/what-is-the-use-case-for-delegate/1180/6 "2019-09-30T05:38:09Z")

</div>

> [@girng\_github](#):
>
> That would be a local variable, not an ivar?

No because you can’t share a local variable between methods. An ivar is able to be referenced from any instance methods within the class, as its tied to the object instance not a specific method.

> [@girng\_github](#):
>
> That’s even worse though, because now the developer has to add a `delegate` to any type they delegated, \*\*just to use an innate METHOD that already exists for that type. That’s an unnecessary step and is objectively a negative.

Then just dont use it. It has its uses when, like in my validator example, you want an easier way to write a shortcut method to “delegate” a specific method to an internal ivar/method, without writing out a whole new method for it. You shouldn’t go around creating wrapper types and delegating all the methods to that internal ivar, as that’s kinda pointless.

---

<div class="post-metadata">

**Author:** ![girng\_github](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/girng_github/32/571_2.png) [@girng\_github](https://forum.crystal-lang.org/u/girng_github)\
**Post date:** [September 30, 2019, 5:39am UTC](https://forum.crystal-lang.org/t/what-is-the-use-case-for-delegate/1180/7 "2019-09-30T05:39:58Z")

</div>

So…a developer can’t use an `innate` method of a type, like so:

```auto
class StringWrapper
  def initialize(@string : String)
  end

  delegate downcase, to: @string
end

wrapper = StringWrapper.new "hello"
wrapper.downcase        
pp wrapper.capitalize      

```

Outputs:

> error in line 12  
> Error: undefined method ‘capitalize’ for StringWrapper

They now, even after writing `.capitalize` after the variable name, need to add another delegate to support `capitalize` so it can be used, while [String](https://crystal-lang.org/api/0.31.0/String.html#capitalize(options=Unicode::CaseOptions::None)-instance-method) already supports a `capitalize` method?

So it would look like this:

```auto
class StringWrapper
  def initialize(@string : String)
  end

  delegate downcase, to: @string
  delegate capitalize, to: @string
end

wrapper = StringWrapper.new "hello"
wrapper.downcase       
pp wrapper.capitalize  

```

?

---

<div class="post-metadata">

**Author:** ![Blacksmoke16](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/blacksmoke16/32/1241_2.png) [@Blacksmoke16](https://forum.crystal-lang.org/u/Blacksmoke16)\
**Post date:** [September 30, 2019, 5:44am UTC](https://forum.crystal-lang.org/t/what-is-the-use-case-for-delegate/1180/8 "2019-09-30T05:44:21Z")

</div>

Yes but that is a contrived example just showing how `delegate` works. Given that specific class as it is there is no point for it to exist when you can just define a local variable like `"hello"` and use that.

It becomes more useful when you replace string with a custom type. Again please do realize that `delegate` is nothing more than a helper macro like `property` or `getter`. There is no magic going on here.

---

<div class="post-metadata">

**Author:** ![girng\_github](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/girng_github/32/571_2.png) [@girng\_github](https://forum.crystal-lang.org/u/girng_github)\
**Post date:** [September 30, 2019, 5:47am UTC](https://forum.crystal-lang.org/t/what-is-the-use-case-for-delegate/1180/9 "2019-09-30T05:47:46Z")

</div>

> [@Blacksmoke16](#):
>
> No because you can’t share a local variable between methods. **An ivar is able to be referenced from any instance methods within the class, as its tied to the object instance not a specific method.**

To bold: Why would a developer want a specific ivar to _not_ be exposed?

If it’s an ivar, it should be freely available as it’s a property of a class, no?

Why is it “hidden” when used with a delegate. Doesn’t make sense, and seems overly complex for what it’s doing. Especially when the alternatives are much simpler and offer far more explicitness, and most importantly, allow the developer to use innate methods of a type and not restrict them to “delegated methods”.

Which now, the developer has to add a new delegate whenever they want to call a method, instead of just calling that method that is innate to that type (which already exists!). Again, an added layer of complexity that shouldn’t be there.

---

<div class="post-metadata">

**Author:** ![Blacksmoke16](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/blacksmoke16/32/1241_2.png) [@Blacksmoke16](https://forum.crystal-lang.org/u/Blacksmoke16)\
**Post date:** [September 30, 2019, 5:56am UTC](https://forum.crystal-lang.org/t/what-is-the-use-case-for-delegate/1180/10 "2019-09-30T05:56:13Z")

</div>

> [@girng\_github](#):
>
> To bold: Why would a developer want a specific ivar to _not_ be exposed?
> 
> If it’s an ivar, it should be freely available as it’s a property of a class, no?

If it’s an implementation detail and not part of the public API. There are quite a few examples in the standard library, for Hash, JSON::PullParser, etc.

> [@girng\_github](#):
>
> Why is it “hidden” when used with a delegate. Doesn’t make sense, and seems overly complex for what it’s doing. Especially when the alternatives are much simpler and offer far more explicitness, and most importantly, allow the developer to use innate methods of a type and not restrict them to “delegated methods”.
> 
> Which now, the developer has to add a new delegate whenever they want to call a method, instead of just calling that method that is innate to that type. Again, an added layer of complexity that shouldn’t be there.

Again, mainly for the implementation detail and only wanting to expose what the user needs. Functionally there is no difference between

```auto
class Klass 
  getter validator : Validator = Validator.new
end

Klass.new.validator.valid? "foo"

```

```auto
class Klass 
  delegate :valid?, to: @validator

  @validator : Validator = Validator.new
end

Klass.new.valid? "foo"

```

```auto
class Klass 
  @validator : Validator = Validator.new

  def valid?(value : String)
    @validator.valid? value
  end
end

Klass.new.valid? "foo"

```

They all work the same, just the the last 2 do not allow the user to access the actual `@validator` object. If it’s okay for the user to access that then the first example would be fine, or could be used in combination with one of the latter two examples to eliminate the need to include the `.validator` when wanting to call `valid?` while still exposing the full object to the user.

---

<div class="post-metadata">

**Author:** ![girng\_github](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/girng_github/32/571_2.png) [@girng\_github](https://forum.crystal-lang.org/u/girng_github)\
**Post date:** [September 30, 2019, 6:14am UTC](https://forum.crystal-lang.org/t/what-is-the-use-case-for-delegate/1180/11 "2019-09-30T06:14:41Z")

</div>

> [@Blacksmoke16](#):
>
> If it’s okay for the user to access that

I believe it’s always okay for a user to access that? Why is restricting a developer access to something ever okay?

That code doesn’t compile for me btw. And I have no idea what you are trying to explain with those code examples. That you like the word `validator`? ![](https://forums.d2jsp.org/html/emoticons/wallbash.gif)

---

<div class="post-metadata">

**Author:** ![Blacksmoke16](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/blacksmoke16/32/1241_2.png) [@Blacksmoke16](https://forum.crystal-lang.org/u/Blacksmoke16)\
**Post date:** [September 30, 2019, 6:33am UTC](https://forum.crystal-lang.org/t/what-is-the-use-case-for-delegate/1180/12 "2019-09-30T06:33:38Z")

</div>

> [@girng\_github](#):
>
> I believe it’s always okay for a user to access that? Why is restricting a developer access to something ever okay?

Again for the third time, if its an implementation detail and shouldn’t be used by the end user. The developer should be using the public API, as its the main interface for interacting with an object. The public API won’t change without some warning, while the internals of how that object functions can change at will and break the developer’s application if they were relying on it.

> [@girng\_github](#):
>
> That code doesn’t compile for me btw. And I have no idea what you are trying to explain with those code examples. That you like the word `validator` ? ![](https://forums.d2jsp.org/html/emoticons/wallbash.gif)

It does if you scroll up and look at the full example [What is the use case for delegate? - #2 by Blacksmoke16](https://forum.crystal-lang.org/t/what-is-the-use-case-for-delegate/1180/2). I’m going to bed now, so i’ll try one more time to explain what is going on.

`delegate` is a helper macro, just like `property` or `getter` that simply expands to define a method that calls some other method on the delegated type. E.x.

```auto
delegate :valid?, to: @validator
# Expands to
def valid?(*args, **options)
 @validator.valid?(*args, **options)
end

```

There is no magic going on here.

The first example was showing how it would work without delegate and with the validator object exposed in the public API. The second example was showing how it would work with delegate and the validator object being an implementation detail. The third example is essentially the same as the second, but showing what the delegate does without actually using it. A fourth example could be added like

```auto
class Klass 
  delegate :valid?, to: @validator

  getter validator : Validator = Validator.new
end

obj = Klass.new

# The developer can get the full validator object
val = obj.validator

# Which can call its #valid? method
valid = val.valid? "bar"

# The developer also has a shortcut method to the validators #valid? method directly on `Klass`
obj.valid? "foo"

```

I don’t agree with your argument about it being “anti-brevity” as IMO its more clear to what its doing than having to manually define the methods. In the end it’s just a tool in the developer’s toolbox to help reduce boilerplate like `property` and `getter`, or `record` does. Any dev new to any language is going to have a learning curve, saying something shouldn’t exist just because someone new has to learn it doesn’t mean it’s a bad thing that should go away.

---

<div class="post-metadata">

**Author:** ![girng\_github](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/girng_github/32/571_2.png) [@girng\_github](https://forum.crystal-lang.org/u/girng_github)\
**Post date:** [September 30, 2019, 6:46am UTC](https://forum.crystal-lang.org/t/what-is-the-use-case-for-delegate/1180/13 "2019-09-30T06:46:28Z")

</div>

> [@Blacksmoke16](#):
>
> Again for the third time, if its an implementation detail and shouldn’t be used by the end user. The developer should be using the public API, as its the main interface for interacting with an object. The public API won’t change without some warning, while the internals of how that object functions can change at will and break the developer’s application if they were relying on it.

Restricting the end-user to only a public API is bad design and very limiting. For example, there are cases where the end-user can’t access a certain method that is private, which could help them. I’ve seen this in Godot’s repo numerous times where a user couldn’t access a method/variable in a class. They had to create a GitHub issue and ask for it to become `public`. Restricting access to methods/variables is never a good idea, and it ultimately will waste the time of contributors and lead developers.

> [@Blacksmoke16](#):
>
> I don’t agree with your argument about it being “anti-brevity” as IMO its more clear to what its doing than having to manually define the methods

My argument is you don’t need to “manually define the methods”, because those methods are innately inherited from the base type (String) in this case. Adding another `delegate` line just to access a method that is already accessible is an unnecessary step, and doesn’t make any sense. It’s.. **redundant**.

I think you are proving my point. All that code you are trying to show me is unnecessary and overly complex, for no reason other than “oh my gawd, I want to restrict a user to access something!” which is inherently flawed.

**Developers should have access to any method, variable, or whatever, it’s their project.**

## Definition of _their_

1 **:** of or relating to them or themselves especially as possessors, [agents](https://www.merriam-webster.com/dictionary/agent), or objects of an action

**Possessor** is the keyword here. We own the code we are writing, if you own something, you should be allowed access to it whenever you want.

This delegate macro is equivalent to owning a computer (that you paid for), but you can’t plug anything into the USB port without first asking your parents. It’s extremely silly, restrictive, and makes no sense. You should freely be able to plug in whatever you want into that USB port without asking for permission.

---

<div class="post-metadata">

**Author:** ![Exilor](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/exilor/32/780_2.png) [@Exilor](https://forum.crystal-lang.org/u/Exilor)\
**Post date:** [September 30, 2019, 8:32am UTC](https://forum.crystal-lang.org/t/what-is-the-use-case-for-delegate/1180/14 "2019-09-30T08:32:24Z")

</div>

Consider a class that intends to offer mutable string functionality.

```
class MutableString
  @chars = [] of Char

  delegate size, to: @chars
end

```

You’re arguing that one should be able to access `@chars` directly to ask for its size.  
Okay, this is currently implemented as an array of Char and therefore it makes sense to just use that array’s size to get the size of the mutable string.  
But consider what would happen if I decided that the way to go is to implement MutableString differently and now internally uses an array of bytes, or a pointer, or whatever.  
Now the `#size` method must be implemented in some other way, but whoever uses  
MutableString doesn’t need to know or care about how I go about making it work, only that when they call #size they get the correct answer. That’s what an implementation detail is. You design an interface that users can rely on, and the way you manage to get it working is your problem as a developer, not the user’s.

If in the future you find that a class in Crystal hides something that you want to use, just override whatever you need to override to suit your needs. That’s one possible use of Crystal being as open as it is. But if the implementation changes and your code stops working because you rely on the internal workings of something it will be up to you to adapt.

---

<div class="post-metadata">

**Author:** ![girng\_github](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/girng_github/32/571_2.png) [@girng\_github](https://forum.crystal-lang.org/u/girng_github)\
**Post date:** [September 30, 2019, 9:00am UTC](https://forum.crystal-lang.org/t/what-is-the-use-case-for-delegate/1180/15 "2019-09-30T09:00:54Z")

</div>

> [@Exilor](#):
>
> But consider what would happen if I decided that the way to go is to implement MutableString differently and now internally uses an array of bytes, or a pointer, or whatever.  
> Now the `#size` method must be implemented in some other way, **but whoever uses**  
> **MutableString doesn’t need to know or care about how I go about making it work, only that when they call #size they get the correct answer.**

I actually agree with this (bolded). However, a developer might need to access that “internal pointer, array of bytes, etc”. That’s why I don’t understand why it has to be “protected” or “private”.

What is wrong with allowing the user to have access to it? If they access it and it breaks, that’s their problem. If they access it and it fixes their issue (this is a good thing!)

---

<div class="post-metadata">

**Author:** ![Exilor](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/exilor/32/780_2.png) [@Exilor](https://forum.crystal-lang.org/u/Exilor)\
**Post date:** [September 30, 2019, 9:19am UTC](https://forum.crystal-lang.org/t/what-is-the-use-case-for-delegate/1180/16 "2019-09-30T09:19:53Z")

</div>

For the same reason you’re not allowed entry to a restaurant’s kitchen. You’re there to eat what they serve, not to argue with the cook and tinker with the stove.

Crystal is more lax than that. There are ways to circumvent any attempt of encapsulation if need be. But establishing a clear demarcation between _what_ your class provides and _how_, is a good thing.

---

<div class="post-metadata">

**Author:** ![girng\_github](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/girng_github/32/571_2.png) [@girng\_github](https://forum.crystal-lang.org/u/girng_github)\
**Post date:** [September 30, 2019, 9:24am UTC](https://forum.crystal-lang.org/t/what-is-the-use-case-for-delegate/1180/17 "2019-09-30T09:24:39Z")

</div>

I don’t see it as a demarcation, I see it as a limiting factor which is a hindrance to the developer.

I’m not not allowed into a restaurant’s kitchen because I don’t own the place, I’m a customer.

I own my code I write, I am the Chef. I can go into my kitchen whenever I want, for any reason. Same should be true for code (access anything I want, at anytime).

---

<div class="post-metadata">

**Author:** ![Exilor](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/exilor/32/780_2.png) [@Exilor](https://forum.crystal-lang.org/u/Exilor)\
**Post date:** [September 30, 2019, 9:28am UTC](https://forum.crystal-lang.org/t/what-is-the-use-case-for-delegate/1180/18 "2019-09-30T09:28:03Z")

</div>

You do own the code you write. Go ahead and don’t ever use private and protected methods/classes/properties.  
Others will likewise do, with the code that they write, as they see fit.  
And in the end we’re all happy.

---

<div class="post-metadata">

**Author:** ![girng\_github](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/girng_github/32/571_2.png) [@girng\_github](https://forum.crystal-lang.org/u/girng_github)\
**Post date:** [September 30, 2019, 9:31am UTC](https://forum.crystal-lang.org/t/what-is-the-use-case-for-delegate/1180/19 "2019-09-30T09:31:06Z")

</div>

Thank you.

Yes, it’s just hard because when I see these kinds of keywords out in the wild, it confuses me to no end. Maybe I should just worry about my own code.

---

<div class="post-metadata">

**Author:** ![mavu](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/mavu/32/213_2.png) [@mavu](https://forum.crystal-lang.org/u/mavu)\
**Post date:** [September 30, 2019, 10:12pm UTC](https://forum.crystal-lang.org/t/what-is-the-use-case-for-delegate/1180/20 "2019-09-30T22:12:18Z")

</div>

In some cases people with more experience actually do know what they are doing and why.

You can write code in any way you like, but it can be beneficial to listen to those people and learn from them. There almost always is a reason for “the way things are done” as there are reasons why other things are not done.

You might be one of those people who only learn from their own mistakes, and refuse to learn from others. That is fine too, just be aware that you are ignoring years of experience and knowledge that way.

[Next page](https://forum.crystal-lang.org/t/what-is-the-use-case-for-delegate/1180.md?page=2)
