[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: API Design
- From: Hugo Musso Gualandi <hgualandi@...>
- Date: Mon, 18 Sep 2017 23:31:25 -0300
>
> As you can see the arguments are inconsistent;
> either (number, content) or (number) or (content)
> Any ideas how to reconcile that?
>
In cases like this I like having a different constructor for each case:
b1 = Buffer.new(1024)
b2 = Buffer.fromString("hello world")
b3 = Buffer.fromBuffer(b2, 14)
One advantage of separating the functions is that if you have a type
error in your code and pass the wrong value to the constructor you get
an error immediately instead of the program silently doing the wrong
thing.