With a bit of fiddeling you can use every kind of bracket to basically make function calls in c++

Here are the links to the snippets, all compile and run

Rust: https://godbolt.org/z/bM3d7bG14

OCaml: https://godbolt.org/z/17oMv83zx

C++: https://godbolt.org/z/9Y3WfoE1W

all 30 comments

sorted by: hot top controversial new old
[–] 3 points 2 hours ago

Ehh, who needs functions anyways, you got one big one and thats your whole codebase.

  • source
  • [–] 9 points 6 hours ago* (3 children)

    Funny that you put rust as the "uses parenthesis for function calls". When in rust you can use any bracket for macro invocations:

    let v1 = vec!(1,2,3);
    let v2 = vec![1,2,3];
    let v3 = vec!{1,2,3};
    

    These are valid and have the exact same meaning.

  • source
  • hideshow 3 child comments
  • [–] 2 points 6 hours ago (1 child)

    To be fair, with Rust macros anything goes. There was an example where someone demoed descriping rust structs and enums nested as xml with a macro to parse it.

  • source
  • parent
  • hideshow 1 child comment
  • [–] 1 point 4 hours ago

    That's inside the macro though. Whatever you parse inside the macro is defined by the creator of the macro. The macro invocation itself is defined by the rust language.

    Rust allows you to use any bracket because it doesn't know what the macro is supposed to do.

    Some macros work like functions:

    println!("Hello world");
    

    Some macros work like array declarations:

    let v = vec![1,2,3];
    

    And some macros work like a code scope:

    select!{
     a => myfunc(),
     b => my_other_func()
    }
    

    Since rust doesn't know what your macro does, it just lets the user choose whatever the user sees more fitting for that specific macro invocation.

  • source
  • parent
  • [–] 23 points 9 hours ago (8 children)

    cpp and their operator overloads are also insane. It makes understanding cpp code impossible. A "+" could actually do something completely different or have insane side-effects. Truly superior language for spreading confusion.

  • source
  • hideshow 8 child comments
  • [–] 20 points 9 hours ago (4 children)

    Operator overloads is something that sounds like a good idea until you experience them firsthand. Just properly name your functions for fuck’s sake.

  • source
  • parent
  • hideshow 4 child comments
  • [–] 5 points 5 hours ago

    Operator overloading is awesome in a functional language. Haskell allows for a lot of creative stuff with operators, but since they can't have side effects, must conform to predictable types, and have specific requirements they are somewhat understandable. Idris is also very ergonomic when it comes to operators.

    C++ allowing a library to override the + operator with system("rm -rf /") is a lot less awesome.

  • source
  • parent
  • [–] 3 points 5 hours ago

    As a computational physicist, I appreciate operator overloading IF used properly.
    Example of a good use: + for matrix addition
    Example of a bad use: left shift operator << as a pipe
    I still don't understand who's in the C++ committee that they would choose this garbage over a function

  • source
  • parent
  • [–] 3 points 7 hours ago (1 child)

    Honestly, I'm glad to have them, it can make a number of things simpler. For instance, a program I wrote had a number of duration fields that had to be stored in XML files and updated every once in a while. It was something that had to occur very often in the code: add a value to the duration, set that value in the XML data, and save the XML file. So I created a class that stored the date/time value and a pointer the XML element (it could be assumed that nothing else would be changing the value in the XML file and if it did, then that change should be overwritten) and overloaded the += operator (among others), so then all I needed was to create the DurationField object, and then I could go durationFieldX += time2 - time1 for instance. I could abstract all the logic away and make it very clear and easy to write. Could I have made it so that I have to to durationFieldX.add(time2 - time1)? Of course I could have. But IMO that variant is less neat and less readable.

  • source
  • parent
  • hideshow 1 child comment
  • [–] 4 points 6 hours ago

    I'll jump on your unpopular side. With a decent IDE you should be able to point/click and decode what any operator is doing in any context. If I have two vectors, or quaternions, and I want to operate on them, why should I be forced to pass them to a standard function instead of clearly seeing what I'm doing. If you can't be bothered to know the types of your variables in a strongly typed language... IDK.

  • source
  • parent
  • [–] 10 points 8 hours ago (5 children)

    I have honestly never seen parentheses called "round brackets" before. It totally makes sense, I have no idea why it's not used more often.

  • source
  • hideshow 5 child comments
  • [–] 6 points 5 hours ago (2 children)

    Might be a German thing. For us, they are all "Klammern" and we call them either round (rund), angular (eckig) or curved (geschweift).

  • source
  • parent
  • hideshow 2 child comments
  • [–] 5 points 7 hours ago (2 children)

    Good meme, but I'm really not sure why you wrapped everything in asserts which kind of ruins the aesthetics. IMO would have worked better as e.g.:

    x = sum(1, 2, 3); // x = 6
    
  • source
  • hideshow 2 child comments
  • [–] 11 points 9 hours ago* (1 child)

    Only one of those is a function, get it right. () Call functions <> Specialize Templates, can be used to do compile time calls to things that behave like functions. [] Accesses elements {} Calls constructors, aka functions that do the initial setup.

    Overloading these to do something else gets you in the naughty corner.

    Edit: the implementation of the {} fuckery is no great. Just save the sum instead of all numbers.

  • source
  • hideshow 1 child comment
  • [–] [S] 5 points 9 hours ago

    Good point regarding the {} implementation.

    I disagree slightly regarding your point that these aren't function calls. Yes technically they are different things but effectively they are functions, I cann pass arguments and get a result based on some operations.

    Of course not all of these can do anything but only the constexpr value is actually pretty limited. The other ones are straight up functions

  • source
  • parent
  • [–] 7 points 9 hours ago (3 children)

    I haven't kept up to date with C++ development in the last 16 years, I only recognize the first two of those four.

  • source
  • hideshow 3 child comments
  • [–] [S] 7 points 9 hours ago (1 child)

    You can overload the indexing operazor "[]" (std::vector does this for example), and since c++23 this operator can have more than one argument.

    The last one is a constructor call with an overloaded conversion operator. The {} syntax is possible since c++11 I think. The conversion operator was already available before that

  • source
  • parent
  • hideshow 1 child comment
  • [–] 2 points 8 hours ago

    You can do most if not all of this in Perl if you're twisted enough. Some hoop jumping may be required*, but I can think of ways to do something that looks like each of these.

    *: The braces are especially tricky if warnings are turned on. I'd probably abuse the deprecated multidimensional syntax and tie a hash to the actual function.

  • source