Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #85508
| From | Cholo Lennon <chololennon@hotmail.com> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Function overloading |
| Date | 2022-07-20 18:42 -0300 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <tb9ssj$s32$1@gioia.aioe.org> (permalink) |
I am learning Rust. One missing C++/Java feature is function
overloading. One of the explanations of this decision is that "function
overloading is an anti-pattern", because, among other things, "it leads
to less readable and understandable code".
This surprised me because I consider it very useful. I really hate
having to code multiple functions with different names and almost the
same functionality. I suffered this in Python (its solution based in
decorators is not the best), and also in Typescript (its solution based
in several prototypes for a single function is really awful).
What is your opinion about the function overloading as an
"anti-pattern"? is it?
Disclaimer: "Overloading" where only types differ (but the number of
parameters are the same) is possible in Rust using generic traits,
something like the following:
struct MyPrinter;
trait Printer<T> {
fn print(&self, value: T);
}
impl Printer<i32> for MyPrinter {
fn print(&self, value: i32) {
println!("Value: {}", value);
}
}
impl Printer<&str> for MyPrinter {
fn print(&self, value: &str) {
println!("Value: {}", value);
}
}
fn main() {
let foo = MyPrinter;
foo.print(10);
foo.print("Hello");
}
--
Cholo Lennon
Bs.As.
ARG
Back to comp.lang.c++ | Previous | Next — Next in thread | Find similar | Unroll thread
Function overloading Cholo Lennon <chololennon@hotmail.com> - 2022-07-20 18:42 -0300
Re: Function overloading Lynn McGuire <lynnmcguire5@gmail.com> - 2022-07-20 19:22 -0500
Re: Function overloading Gawr Gura <gawrgura@mail.hololive.com> - 2022-07-20 22:44 -0700
Re: Function overloading Lynn McGuire <lynnmcguire5@gmail.com> - 2022-07-21 16:17 -0500
Re: Function overloading Cholo Lennon <chololennon@hotmail.com> - 2022-07-22 19:43 -0300
Re: Function overloading Lynn McGuire <lynnmcguire5@gmail.com> - 2022-07-22 18:38 -0500
Re: Function overloading Cholo Lennon <chololennon@hotmail.com> - 2022-07-24 01:24 -0300
Re: Function overloading Lynn McGuire <lynnmcguire5@gmail.com> - 2022-07-25 16:01 -0500
Re: Function overloading "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2022-07-26 00:05 +0200
Re: Function overloading Cholo Lennon <chololennon@hotmail.com> - 2022-07-30 18:04 -0300
Re: Function overloading Cholo Lennon <chololennon@hotmail.com> - 2022-07-30 18:03 -0300
Re: Function overloading Lynn McGuire <lynnmcguire5@gmail.com> - 2022-08-02 23:11 -0500
Re: Function overloading Bonita Montero <Bonita.Montero@gmail.com> - 2022-07-27 16:10 +0200
Re: Function overloading Bonita Montero <Bonita.Montero@gmail.com> - 2022-07-27 16:11 +0200
Re: Function overloading Bonita Montero <Bonita.Montero@gmail.com> - 2022-07-27 16:35 +0200
Re: Function overloading Bonita Montero <Bonita.Montero@gmail.com> - 2022-07-28 05:51 +0200
Re: Function overloading Lynn McGuire <lynnmcguire5@gmail.com> - 2022-07-27 14:54 -0500
Re: Function overloading Bonita Montero <Bonita.Montero@gmail.com> - 2022-07-28 05:43 +0200
Re: Function overloading Lynn McGuire <lynnmcguire5@gmail.com> - 2022-07-28 13:32 -0500
Re: Function overloading Lynn McGuire <lynnmcguire5@gmail.com> - 2022-07-27 15:01 -0500
Re: Function overloading Juha Nieminen <nospam@thanks.invalid> - 2022-07-21 05:45 +0000
Re: Function overloading Paavo Helde <eesnimi@osa.pri.ee> - 2022-07-21 09:04 +0300
Re: Function overloading Juha Nieminen <nospam@thanks.invalid> - 2022-07-21 07:16 +0000
Re: Function overloading Lynn McGuire <lynnmcguire5@gmail.com> - 2022-07-21 16:22 -0500
csiph-web