Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. What "advanced" features of programming languages do you use?

What "advanced" features of programming languages do you use?

Scheduled Pinned Locked Moved The Lounge
c++javascripttutorialquestion
35 Posts 17 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • OriginalGriffO OriginalGriff

    And you get far too many who just go "sod it, I can't be assed":

    var x = 6;
    foreach (var x in y.GetAll())
    ...

    There is a good blog post on it here: The Use and Abuse of the C# “var” Keyword[^]

    "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony AntiTwitter: @DalekDave is now a follower!

    D Offline
    D Offline
    Dan Neely
    wrote on last edited by
    #26

    idiots can write unreadable code in any language. X|

    Did you ever see history portrayed as an old man with a wise brow and pulseless heart, weighing all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt

    1 Reply Last reply
    0
    • F F ES Sitecore

      I use something called a "debugger". I always knew this was quite a maverick thing to do, but looking at the QA section I didn't realise just how maverick!

      R Offline
      R Offline
      Rick York
      wrote on last edited by
      #27

      You rebel you.

      "They have a consciousness, they have a life, they have a soul! Damn you! Let the rabbits wear glasses! Save our brothers! Can I get an amen?"

      1 Reply Last reply
      0
      • Z ZurdoDev

        RugbyLeague wrote:

        it removes a lot of unnecessary noise

        Like being able to look at the declaration of a variable and know what type of object it is? ;)

        Social Media - A platform that makes it easier for the crazies to find each other. Everyone is born right handed. Only the strongest overcome it. Fight for left-handed rights and hand equality.

        T Offline
        T Offline
        TheGreatAndPowerfulOz
        wrote on last edited by
        #28

        Other than what it was invented for (linq statements and anonymous types) an example of a good use of var is: var foo = new SomeReallyLongTemplateDeclaration>>; Here, you know what type foo is because it's type is readily apparent on the right-hand side of the statement. Basically if you can readily determine the type from the right-hand side, then it's ok to use var. Otherwise, declare the type instead of using var. So here, not so good: var boo = SomeFunction();

        #SupportHeForShe Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun

        1 Reply Last reply
        0
        • Sander RosselS Sander Rossel

          Try reading it as a trimmed down function (which now also allow for an arrow instead of curly braces).

          // If you'd write an actual function on a single line:
          myCollection.Where(bool IsActive(MyObject x) { return x.IsActive; });

          // Replace the {} with =>, the ; can then also be removed:
          myCollection.Where(bool IsActive(MyObject x) => return x.IsActive);

          // The return statement isn't necessary:
          myCollection.Where(bool IsActive(MyObject x) => x.IsActive);

          // Neither is a function name:
          myCollection.Where(bool (MyObject x) => x.IsActive);

          // Types can usually be inferred:
          myCollection.Where((x) => x.IsActive);

          // Remove redundant parenthesis:
          myCollection.Where(x => x.IsActive);

          It is pretty close to the mathematical notation. Unfortunately, it doesn't always work that well.

          // Example with multiple arguments, here you need parenthesis again:
          myCollection.Where((x, y) => x.IsActive && y > 10);

          // Sometimes the type can't be inferred:
          myCollection.Where((MyObject x, int y) => x.IsActive && y > 10);

          // You can (always) use full argument names if you like, although a single letter is common:
          myCollection.Where((collectionItem, index) => collectionItem.IsActive && index > 10);

          Hope this explains it even further.

          Best, Sander sanderrossel.com Migrating Applications to the Cloud with Azure arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #29

          Thank you very much, yes this helps I think

          It does not solve my Problem, but it answers my question

          1 Reply Last reply
          0
          • R rjmoses

            I've been digging into a javascript based application lately and tripped across some code that made extensive use of the arity (which is deprecated now), currying capabilities and anonymous functions. Took me a lonnnnnng time to understand what the intent and operation of the code was. So, out of curiosity, I'm wondering what "advanced" features of people's favorite languages they use on a regular basis, how they use them, and why? Or, which ones do you seldom/never use because.... E.g: ....I like using lambdas in C++ because .... (I can't think of a good example because I avoid them!) ....I avoid lambdas in C++ because they are often used where a simple function would be clearer and more readable (truth in advertising).

            H Offline
            H Offline
            honey the codewitch
            wrote on last edited by
            #30

            I use C# var extensively (basically C++ auto) in protest of lack of proper typedef support in C#

            Real programmers use butterflies

            1 Reply Last reply
            0
            • R rjmoses

              I've been digging into a javascript based application lately and tripped across some code that made extensive use of the arity (which is deprecated now), currying capabilities and anonymous functions. Took me a lonnnnnng time to understand what the intent and operation of the code was. So, out of curiosity, I'm wondering what "advanced" features of people's favorite languages they use on a regular basis, how they use them, and why? Or, which ones do you seldom/never use because.... E.g: ....I like using lambdas in C++ because .... (I can't think of a good example because I avoid them!) ....I avoid lambdas in C++ because they are often used where a simple function would be clearer and more readable (truth in advertising).

              G Offline
              G Offline
              Gary R Wheeler
              wrote on last edited by
              #31

              While I use lambdas in my C# code, I don't consider them especially 'advanced'. Most of the time I'm actually averse to using such features in any language, because they tend to encourage writing clever code rather than maintainable code. Since I have code in the field older than some of you folks reading this, maintainable wins. I sporadically read news about new C++ features. None of them inspire me, as they whiff strongly of compiler weenies saying "look what I can do!". They are also overly-reliant on templates, and I find the syntax clumsy and verbose. I consider myself well-skilled in C++, and look for productivity-enhancing changes to the language. They're few and far between. C# is somewhat a different story. Most of the features I read about seem designed to improve productivity and code quality, even when they are dismissed as 'syntactic sugar'.

              Software Zen: delete this;

              R 1 Reply Last reply
              0
              • R rjmoses

                I've been digging into a javascript based application lately and tripped across some code that made extensive use of the arity (which is deprecated now), currying capabilities and anonymous functions. Took me a lonnnnnng time to understand what the intent and operation of the code was. So, out of curiosity, I'm wondering what "advanced" features of people's favorite languages they use on a regular basis, how they use them, and why? Or, which ones do you seldom/never use because.... E.g: ....I like using lambdas in C++ because .... (I can't think of a good example because I avoid them!) ....I avoid lambdas in C++ because they are often used where a simple function would be clearer and more readable (truth in advertising).

                S Offline
                S Offline
                Stefan_Lang
                wrote on last edited by
                #32

                I find it interesting that many seem to think 'var' is such a bad thing. In C++, there's the auto keyword, and there's even the complementary keyword decltype which is particularly useful when you want the result type of an expression, or the return type of a function. As I understand it, auto fills a similar role as var does in other language(s?), and there's actually a coding guideline promoted by Herb Sutter, no less, to 'aaa', or 'almost always [use] auto'. One of the main reasons is to help enforce type safety, which of course is outstandingly important in C++, probably more than in any other language. Another reason is maintainability: every use of auto probably doesn't need to be changed when you change some type in your code later. That said, I often deliberately don't use auto, for one (or both) of two reasons: helping with autocompletion (the editor sometimes won't know what member variables and methods to suggest when dereferencing an auto variable), readability (provided the type name is easy enough to read, rather than a nested::with), and disambiguation (when I want the value to remain unchanged - i. e. const - rather than modifiable). I suspect the former will no longer be a reason when we finally manage to switch to a newer IDE version later this year, that's why I said two reasons ;)

                GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)

                Greg UtasG 1 Reply Last reply
                0
                • G Gary R Wheeler

                  While I use lambdas in my C# code, I don't consider them especially 'advanced'. Most of the time I'm actually averse to using such features in any language, because they tend to encourage writing clever code rather than maintainable code. Since I have code in the field older than some of you folks reading this, maintainable wins. I sporadically read news about new C++ features. None of them inspire me, as they whiff strongly of compiler weenies saying "look what I can do!". They are also overly-reliant on templates, and I find the syntax clumsy and verbose. I consider myself well-skilled in C++, and look for productivity-enhancing changes to the language. They're few and far between. C# is somewhat a different story. Most of the features I read about seem designed to improve productivity and code quality, even when they are dismissed as 'syntactic sugar'.

                  Software Zen: delete this;

                  R Offline
                  R Offline
                  rjmoses
                  wrote on last edited by
                  #33

                  Writing clever code instead of maintainable---nahh, nobody ever does that. My own criteria is that I want to be able to look at a section of code and "grok" it in a few seconds.

                  1 Reply Last reply
                  0
                  • S Stefan_Lang

                    I find it interesting that many seem to think 'var' is such a bad thing. In C++, there's the auto keyword, and there's even the complementary keyword decltype which is particularly useful when you want the result type of an expression, or the return type of a function. As I understand it, auto fills a similar role as var does in other language(s?), and there's actually a coding guideline promoted by Herb Sutter, no less, to 'aaa', or 'almost always [use] auto'. One of the main reasons is to help enforce type safety, which of course is outstandingly important in C++, probably more than in any other language. Another reason is maintainability: every use of auto probably doesn't need to be changed when you change some type in your code later. That said, I often deliberately don't use auto, for one (or both) of two reasons: helping with autocompletion (the editor sometimes won't know what member variables and methods to suggest when dereferencing an auto variable), readability (provided the type name is easy enough to read, rather than a nested::with), and disambiguation (when I want the value to remain unchanged - i. e. const - rather than modifiable). I suspect the former will no longer be a reason when we finally manage to switch to a newer IDE version later this year, that's why I said two reasons ;)

                    GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)

                    Greg UtasG Offline
                    Greg UtasG Offline
                    Greg Utas
                    wrote on last edited by
                    #34

                    I agree with Sutter about almost always using auto and will even do this:

                    const auto& item = ... ;

                    Another advantage of auto is that there are fewer affected-bys when you rename a type. Another advantage is that auto reduces the number of line splits, which I like to avoid.

                    <p><a href="https://github.com/GregUtas/robust-services-core/blob/master/README.md">Robust Services Core</a>
                    <em>The fox knows many things, but the hedgehog knows one big thing.</em></p>

                    1 Reply Last reply
                    0
                    • Z ZurdoDev

                      Hover over each item each time you want to know what is? If you think that's easier and worth it, I hope you never work on my team. :-D

                      Social Media - A platform that makes it easier for the crazies to find each other. Everyone is born right handed. Only the strongest overcome it. Fight for left-handed rights and hand equality.

                      R Offline
                      R Offline
                      RugbyLeague
                      wrote on last edited by
                      #35

                      The vast majority of the time when looking at code I don't need to know what everything is - so without var I am presented with a load of noise and redundancy. If I want to know what something is and it isn't immediately obvious then I can hover over it and it tells me and for the purpose of that session I don't need to do that again. I prefer to concentrate on the code rather than a load of type declaration noise. Admittedly it is a fine line - I don't use var everywhere - int i = 10 never becomes var i = 10, for example. And using var has become something I have adjusted to over time - at first I didn't like it, then I used it to remove redundancy var l = new List() rather than List l = new List(). Now I use it in most places other than the aforementioned value type decls.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups