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. Is there a programming language...

Is there a programming language...

Scheduled Pinned Locked Moved The Lounge
questioncsharpdatabasecomtesting
72 Posts 26 Posters 0 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.
  • M Marc Clifton

    Gary Wheeler wrote:

    The Ada programming language provided a semblance of semantic typing.

    Ah, it does indeed. I've been reading the Ada type stuff - very slick. It's a pity these constructs aren't in other languages. I wonder why not - it seems like it would really help bullet proof code. Then again, like anything else, I bet it can be horribly abused as well. Marc

    R Offline
    R Offline
    Rob Grainger
    wrote on last edited by
    #39

    Stroustrup has written somewhere on implementing SI measures in C++ using user-defined literals and simple classes. That would work well, but should really be part of the standard library.

    "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

    G 1 Reply Last reply
    0
    • M Marc Clifton

      ...that works "easily" with semantic types? For example, I may have: int age = 51; which completely loses the concept that 51 is an age (in years). What I want is something like: AgeInYears myAge = 51; and yet still be able to specify that I can perform, say, arithmetic operations on "myAge". For example, in C#, I could write:

      class AgeInYears
      {
      public int Value {get;set;}
      }

      ... implement operators on AgeInYears

      But that gets messy real fast - every "semantic type" needs these operators, etc. Furthermore, the unit of measurement is still not handled very elegantly. So, as the question states, are there programming languages out there that are more expressive of semantic types? Marc

      Day 1: Spider Database Navigator Unit Testing Succinctly

      K Offline
      K Offline
      kalberts
      wrote on last edited by
      #40

      CHILL (CCITT HIgh Level Language - CCITT was the old name of ITU-T) probably has the best developed strict type system of any industrial language. One of the features was the distinction between a SYNMODE and NEWMODE definitions (MODE is the CHILL term for type/class): A SYNMODE defines restrictions (like value subranges) or aggregates (like arrays) of existing types, but (within the restrictions) fully compatible with the base mode. A NEWMODE is similar, but defines an incompatible mode. So if you make new integer modes AppleCount and OrangeCount using SYNMODE, you can add apples and oranges. If you define dem using NEWMODE, the compiler won't allow you to add apples and oranges without an explicit cast. CHILL was developed to be the ITU standard for programming telephone switches, but the language design is just as general as, say, c or java. It never made any success in non-telephone environments (and even there it never took more than about half of the market), which is a pity: CHILL is one of the most thoroughly well-designed languages there is. But then again: The marketplace isn't known for always selecting the best designs... (I won't give c as an exapmple of that, that could hurt some people's feelings).

      M 1 Reply Last reply
      0
      • M Marc Clifton

        ...that works "easily" with semantic types? For example, I may have: int age = 51; which completely loses the concept that 51 is an age (in years). What I want is something like: AgeInYears myAge = 51; and yet still be able to specify that I can perform, say, arithmetic operations on "myAge". For example, in C#, I could write:

        class AgeInYears
        {
        public int Value {get;set;}
        }

        ... implement operators on AgeInYears

        But that gets messy real fast - every "semantic type" needs these operators, etc. Furthermore, the unit of measurement is still not handled very elegantly. So, as the question states, are there programming languages out there that are more expressive of semantic types? Marc

        Day 1: Spider Database Navigator Unit Testing Succinctly

        R Offline
        R Offline
        Rob Grainger
        wrote on last edited by
        #41

        Marc has already pointed to Smalltalk, someone else pointed out C++, I'd like to add Haskell to the mix. Getting type safety would be easy:

        newtype meter m = meter m deriving (Show, Num, Eq, Ord)
        newtype foot f = foot f deriving (Show, Num, Eq, Ord)

        -- Usage (ghci> is an iteractive prompt)
        ghci> let m1 = meter 5
        ghci> let m2 = meter 10
        ghci> let m3 = m1 + m2
        ghci> m3
        meter 15
        ghci> let f1 = foot 3
        ghci> let f2 = foot 4
        ghci> let f3 = f1 + f2
        ghci> f3
        foot 7
        ghci> let e1 = f1 + m1 -- Won't Work - produces error of types mismatching

        With more work, it can be extended to add support for conversions, magnitudes (nm, mm, m, km, ...). Indeed someone has already done all this work for us: Dimensional[^] and Dimensional using type families[^]. All available at the standard repository Hackage[^].

        "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

        M 1 Reply Last reply
        0
        • M Marc Clifton

          Gary Wheeler wrote:

          The Ada programming language provided a semblance of semantic typing.

          Ah, it does indeed. I've been reading the Ada type stuff - very slick. It's a pity these constructs aren't in other languages. I wonder why not - it seems like it would really help bullet proof code. Then again, like anything else, I bet it can be horribly abused as well. Marc

          G Offline
          G Offline
          Gary Wheeler
          wrote on last edited by
          #42

          The central goal behind Ada was to make it difficult to make common programming mistakes, and to have the compiler enforce as many conditions for correctness as possible. The language design succeeded in a lot of respects, but it made it difficult to write code in the language. It was very frustrating learning how to appease the compiler. In my case, we were beta testers for one of the first VAX/VMS Ada compilers. It was difficult to tell the difference between genuine flaws in our source and possible compiler bugs.

          Software Zen: delete this;

          1 Reply Last reply
          0
          • S SortaCore

            Cue "who let the dogs out" playing for an unreasonably long time in my head...

            G Offline
            G Offline
            Gary Wheeler
            wrote on last edited by
            #43

            :laugh:

            Software Zen: delete this;

            1 Reply Last reply
            0
            • M Marc Clifton

              ...that works "easily" with semantic types? For example, I may have: int age = 51; which completely loses the concept that 51 is an age (in years). What I want is something like: AgeInYears myAge = 51; and yet still be able to specify that I can perform, say, arithmetic operations on "myAge". For example, in C#, I could write:

              class AgeInYears
              {
              public int Value {get;set;}
              }

              ... implement operators on AgeInYears

              But that gets messy real fast - every "semantic type" needs these operators, etc. Furthermore, the unit of measurement is still not handled very elegantly. So, as the question states, are there programming languages out there that are more expressive of semantic types? Marc

              Day 1: Spider Database Navigator Unit Testing Succinctly

              E Offline
              E Offline
              Eduard Matei
              wrote on last edited by
              #44

              In Python you can inherit from int (something like):

              class AgeInYears(int):
              unit = "years"
              def __new__(cls, age:int):
              cls.age = age
              return int.__new__(cls,age)

              def \_\_str\_\_(self):
                  return "{} {}".format(self.age, self.unit)
              def \_\_add\_\_(self, value:int):
                  self.age += value
                  return self
              

              class User():
              def __init__(self, age:int):
              self.age = AgeInYears(age)

              def \_\_str\_\_(self):
                  return "User: age: {}".format(self.age)
              

              And then use it like:

              user = User(29)
              print(user) #User: age: 29 years
              print(user.age) #29 years
              print(type(user.age)) #

              user.age += 2 #use it like an int, and just increase it.
              print(user.age) #31 years
              print(type(user.age)) #

              Of course, you still have to override some default methods of int (new, add). This should cover the semantics nicely: you have an int, with unit, you can do basic int operations. Ed

              M 1 Reply Last reply
              0
              • E Eduard Matei

                In Python you can inherit from int (something like):

                class AgeInYears(int):
                unit = "years"
                def __new__(cls, age:int):
                cls.age = age
                return int.__new__(cls,age)

                def \_\_str\_\_(self):
                    return "{} {}".format(self.age, self.unit)
                def \_\_add\_\_(self, value:int):
                    self.age += value
                    return self
                

                class User():
                def __init__(self, age:int):
                self.age = AgeInYears(age)

                def \_\_str\_\_(self):
                    return "User: age: {}".format(self.age)
                

                And then use it like:

                user = User(29)
                print(user) #User: age: 29 years
                print(user.age) #29 years
                print(type(user.age)) #

                user.age += 2 #use it like an int, and just increase it.
                print(user.age) #31 years
                print(type(user.age)) #

                Of course, you still have to override some default methods of int (new, add). This should cover the semantics nicely: you have an int, with unit, you can do basic int operations. Ed

                M Offline
                M Offline
                Marc Clifton
                wrote on last edited by
                #45

                Well, that is very snazzy - I'll take a closer look at Python now. Thank you for taking the time to put together that example. Marc

                1 Reply Last reply
                0
                • R Rob Grainger

                  Marc has already pointed to Smalltalk, someone else pointed out C++, I'd like to add Haskell to the mix. Getting type safety would be easy:

                  newtype meter m = meter m deriving (Show, Num, Eq, Ord)
                  newtype foot f = foot f deriving (Show, Num, Eq, Ord)

                  -- Usage (ghci> is an iteractive prompt)
                  ghci> let m1 = meter 5
                  ghci> let m2 = meter 10
                  ghci> let m3 = m1 + m2
                  ghci> m3
                  meter 15
                  ghci> let f1 = foot 3
                  ghci> let f2 = foot 4
                  ghci> let f3 = f1 + f2
                  ghci> f3
                  foot 7
                  ghci> let e1 = f1 + m1 -- Won't Work - produces error of types mismatching

                  With more work, it can be extended to add support for conversions, magnitudes (nm, mm, m, km, ...). Indeed someone has already done all this work for us: Dimensional[^] and Dimensional using type families[^]. All available at the standard repository Hackage[^].

                  "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

                  M Offline
                  M Offline
                  Marc Clifton
                  wrote on last edited by
                  #46

                  Fascinating - I was just reading the Python example below and then looked at your Haskell example. Thanks! Also, I appreciate the links. Marc

                  R 1 Reply Last reply
                  0
                  • K kalberts

                    CHILL (CCITT HIgh Level Language - CCITT was the old name of ITU-T) probably has the best developed strict type system of any industrial language. One of the features was the distinction between a SYNMODE and NEWMODE definitions (MODE is the CHILL term for type/class): A SYNMODE defines restrictions (like value subranges) or aggregates (like arrays) of existing types, but (within the restrictions) fully compatible with the base mode. A NEWMODE is similar, but defines an incompatible mode. So if you make new integer modes AppleCount and OrangeCount using SYNMODE, you can add apples and oranges. If you define dem using NEWMODE, the compiler won't allow you to add apples and oranges without an explicit cast. CHILL was developed to be the ITU standard for programming telephone switches, but the language design is just as general as, say, c or java. It never made any success in non-telephone environments (and even there it never took more than about half of the market), which is a pity: CHILL is one of the most thoroughly well-designed languages there is. But then again: The marketplace isn't known for always selecting the best designs... (I won't give c as an exapmple of that, that could hurt some people's feelings).

                    M Offline
                    M Offline
                    Marc Clifton
                    wrote on last edited by
                    #47

                    Member 7989122 wrote:

                    CHILL (CCITT HIgh Level Language - CCITT was the old name of ITU-T)

                    Interesting! Your description of restrictions, aggregates, base modes, and incompatibility reminds me of what I was reading about Ada. Marc

                    1 Reply Last reply
                    0
                    • G greydmar

                      Well This c++ 11 trick is very powerfull, really! I prefer to do all the hard work from scratch (ok, have R #). I believe that this threshold "semantic" is outside the domain of a programming language (commonly, it is a "system domain" concept), because it is difficult to predict the particularities of a user-defined (conversion, comparison, integrity, serialization, etc.).

                      M Offline
                      M Offline
                      Marc Clifton
                      wrote on last edited by
                      #48

                      greydmar wrote:

                      I believe that this threshold "semantic" is outside the domain of a programming language (commonly, it is a "system domain" concept),

                      Yes, that's what makes it interesting to look at. :) Marc

                      G 1 Reply Last reply
                      0
                      • M Marc Clifton

                        ...that works "easily" with semantic types? For example, I may have: int age = 51; which completely loses the concept that 51 is an age (in years). What I want is something like: AgeInYears myAge = 51; and yet still be able to specify that I can perform, say, arithmetic operations on "myAge". For example, in C#, I could write:

                        class AgeInYears
                        {
                        public int Value {get;set;}
                        }

                        ... implement operators on AgeInYears

                        But that gets messy real fast - every "semantic type" needs these operators, etc. Furthermore, the unit of measurement is still not handled very elegantly. So, as the question states, are there programming languages out there that are more expressive of semantic types? Marc

                        Day 1: Spider Database Navigator Unit Testing Succinctly

                        9 Offline
                        9 Offline
                        9082365
                        wrote on last edited by
                        #49

                        I'm sorry but this has to be amongst the most pointless discursions this forum has ever seen!

                        Quote:

                        int age = 51;

                        A perfect encapsulation of an immutable truth ... age is just a number! What more could you possibly need?

                        M 1 Reply Last reply
                        0
                        • 9 9082365

                          I'm sorry but this has to be amongst the most pointless discursions this forum has ever seen!

                          Quote:

                          int age = 51;

                          A perfect encapsulation of an immutable truth ... age is just a number! What more could you possibly need?

                          M Offline
                          M Offline
                          Marc Clifton
                          wrote on last edited by
                          #50

                          Member 9082365 wrote:

                          A perfect encapsulation of an immutable truth ... age is just a number! What more could you possibly need?

                          OK, what's 34 (besides "just a number") ? Marc

                          9 1 Reply Last reply
                          0
                          • M Marc Clifton

                            Member 9082365 wrote:

                            A perfect encapsulation of an immutable truth ... age is just a number! What more could you possibly need?

                            OK, what's 34 (besides "just a number") ? Marc

                            9 Offline
                            9 Offline
                            9082365
                            wrote on last edited by
                            #51

                            Unless you're a thoroughgoing Pythagorean that question is no more meaningful than 'how is 34?' or 'why is 34?' It is just a number and as we all know (post pi) number doesn't exist in any real sense at all. As written it is an arbitrary typographical representation of a concept within an equally arbitrary logical system that bears no relation other than by extrapolation with what is, was or will be. It is an abstraction. A useful abstraction but an abstraction nonetheless. And doubly so once you bring time into it! Contrary to popular opinion even if we were born simultaneously our real ages are almost certainly different! That's relativity for you!

                            R 1 Reply Last reply
                            0
                            • R Ron Beyer

                              I hate myself for typing this:

                              namespace TestApp1
                              {
                              using AgeInYears = System.Int32;

                              class Program
                              {
                                  static void Main(string\[\] args)
                                  {
                                      AgeInYears myAge = 10;
                                      AgeInYears oldAge = 50;
                                      AgeInYears timeUntilOldAge = oldAge - myAge;
                                  }
                              }
                              

                              }

                              Yes, that's perfectly legal C# code. Its technically an int, works the same way that #define does in c++ to replace types. It only works in single code files though.

                              F Offline
                              F Offline
                              Freak30
                              wrote on last edited by
                              #52

                              You should rewrite it that way.

                              namespace TestApp1
                              {
                              using AgeInYears = System.Int32;

                              class Program
                              {
                                  static void Main(string\[\] args)
                                  {
                                      AgeInYears myAge = 10; // or whatever
                                      AgeInYears timeUntilOldAge = 10;
                                      AgeInYears oldAge = myAge + timeUntilOldAge;
                                  }
                              

                              }
                              }

                              So you are forever young. :)

                              The good thing about pessimism is, that you are always either right or pleasently surprised.

                              1 Reply Last reply
                              0
                              • R Ron Beyer

                                Odd, mine does, VS2013 is what I tried that in. When I typed String.Compare( then hit the down arrow to select one of the overloads that had an int, it showed AgeInYears instead of int.

                                B Offline
                                B Offline
                                BillWoodruff
                                wrote on last edited by
                                #53

                                Interesting; a little investigation shows that a ReSharper trial version (Build 8.1.23.546) is what is making the difference in what shows up in the Intellisense pop-up, where ints are expected. bill

                                If you seek to aid everyone that suffers in the galaxy, you will only weaken yourself … and weaken them. It is the internal struggles, when fought and won on their own, that yield the strongest rewards… If you care for others, then dispense with pity and sacrifice and recognize the value in letting them fight their own battles." Darth Traya

                                1 Reply Last reply
                                0
                                • 9 9082365

                                  Unless you're a thoroughgoing Pythagorean that question is no more meaningful than 'how is 34?' or 'why is 34?' It is just a number and as we all know (post pi) number doesn't exist in any real sense at all. As written it is an arbitrary typographical representation of a concept within an equally arbitrary logical system that bears no relation other than by extrapolation with what is, was or will be. It is an abstraction. A useful abstraction but an abstraction nonetheless. And doubly so once you bring time into it! Contrary to popular opinion even if we were born simultaneously our real ages are almost certainly different! That's relativity for you!

                                  R Offline
                                  R Offline
                                  Rob Grainger
                                  wrote on last edited by
                                  #54

                                  Actually, most people would consider that numbers are as real as most human concepts, if not more so due to their universal applicability. By your logic trees don't exist because "tree" is purely a label we've conjuured up to describe the commonality of all trees. Colours do not exist because "colour" is a word we use to describe colours of all objects. So if anything exists then numbers are as real as anything else - just because they have no physical form does not render then nonexistant. If you reject naming things, then you reject language and symbolic systems as a means of communicating. Good luck with that. I'd suggest Wittgenstein's Philosophical Investigations for a more thorough consideration of this area. More interesting questions he tackles are of the form "what is a game" - now that really is hard to tie down.

                                  "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

                                  9 1 Reply Last reply
                                  0
                                  • M Marc Clifton

                                    ...that works "easily" with semantic types? For example, I may have: int age = 51; which completely loses the concept that 51 is an age (in years). What I want is something like: AgeInYears myAge = 51; and yet still be able to specify that I can perform, say, arithmetic operations on "myAge". For example, in C#, I could write:

                                    class AgeInYears
                                    {
                                    public int Value {get;set;}
                                    }

                                    ... implement operators on AgeInYears

                                    But that gets messy real fast - every "semantic type" needs these operators, etc. Furthermore, the unit of measurement is still not handled very elegantly. So, as the question states, are there programming languages out there that are more expressive of semantic types? Marc

                                    Day 1: Spider Database Navigator Unit Testing Succinctly

                                    A Offline
                                    A Offline
                                    Anas Karm
                                    wrote on last edited by
                                    #55

                                    PROLOG

                                    M 1 Reply Last reply
                                    0
                                    • A Anas Karm

                                      PROLOG

                                      M Offline
                                      M Offline
                                      Marc Clifton
                                      wrote on last edited by
                                      #56

                                      Member 10199043 wrote:

                                      PROLOG

                                      Hmmm. Prolog is an untyped language. Attempts to introduce types date back to the 1980s,[42][43] and as of 2008 there are still attempts to extend Prolog with types.[44] Type information is useful not only for type safety but also for reasoning about Prolog programs. Marc

                                      1 Reply Last reply
                                      0
                                      • M Marc Clifton

                                        Fascinating - I was just reading the Python example below and then looked at your Haskell example. Thanks! Also, I appreciate the links. Marc

                                        R Offline
                                        R Offline
                                        Rob Grainger
                                        wrote on last edited by
                                        #57

                                        Don't know if your familiar with Haskell at all, but its a wonderful thing. One day I'll undwerstand it well enough to use on a real world project. The example given is relatively simple. I particularly like being able to derive properties (type classes) like Ord (a bit like comparable), Num (numeric), Eq (equatable) and Show (convertible to string) automatically for many types. Be aware that "type classes" are not classes in an OO sense at all. More like interfaces. Even more like "concepts" in C++ (when they finally make it into the language). I think I've learned more from learning Haskell than any language since I learned Smalltalk.

                                        "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

                                        M 1 Reply Last reply
                                        0
                                        • R Rob Grainger

                                          Don't know if your familiar with Haskell at all, but its a wonderful thing. One day I'll undwerstand it well enough to use on a real world project. The example given is relatively simple. I particularly like being able to derive properties (type classes) like Ord (a bit like comparable), Num (numeric), Eq (equatable) and Show (convertible to string) automatically for many types. Be aware that "type classes" are not classes in an OO sense at all. More like interfaces. Even more like "concepts" in C++ (when they finally make it into the language). I think I've learned more from learning Haskell than any language since I learned Smalltalk.

                                          "If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.

                                          M Offline
                                          M Offline
                                          Marc Clifton
                                          wrote on last edited by
                                          #58

                                          Rob Grainger wrote:

                                          Don't know if your familiar with Haskell at all, but its a wonderful thing.

                                          Nope, but I've been reading up on it since your previous post!

                                          Rob Grainger wrote:

                                          I think I've learned more from learning Haskell than any language since I learned Smalltalk.

                                          Interestingly, I learned more about the principles of programming from this book[^] than I ever have from any actual comp-sci book. I kid you not - biology and programming have a lot in common. Marc

                                          R 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