Click here to Skip to main content
15,893,401 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: Quick C# quiz Pin
honey the codewitch30-Nov-19 4:25
mvahoney the codewitch30-Nov-19 4:25 
GeneralRe: Quick C# quiz Pin
Sander Rossel30-Nov-19 4:35
professionalSander Rossel30-Nov-19 4:35 
GeneralRe: Quick C# quiz Pin
honey the codewitch30-Nov-19 4:39
mvahoney the codewitch30-Nov-19 4:39 
GeneralRe: Quick C# quiz Pin
PIEBALDconsult30-Nov-19 11:01
mvePIEBALDconsult30-Nov-19 11:01 
GeneralRe: Quick C# quiz Pin
Stuart Dootson1-Dec-19 23:22
professionalStuart Dootson1-Dec-19 23:22 
GeneralRe: Quick C# quiz Pin
honey the codewitch2-Dec-19 3:16
mvahoney the codewitch2-Dec-19 3:16 
GeneralRe: Quick C# quiz Pin
JohaViss611-Dec-19 22:08
professionalJohaViss611-Dec-19 22:08 
GeneralRe: Quick C# quiz Pin
Stuart Dootson1-Dec-19 23:16
professionalStuart Dootson1-Dec-19 23:16 
I have a suspicion that C++ is equally reliant (possibly more so when you get templates involved) on type information
C++
int a(int x) { return x + 1; }

auto b = [](int y) -> int { return y + 1; };

struct C {
  int operator()(int z) const { return z + 1; }
};
C c;

class D {
  int d(int x) const { return x + 1; }
  static int e(int x) { return x + 1; }
public:
  void do_stuff(int a_number) {
    a_number = a(a_number);
    a_number = b(a_number);
    a_number = c(a_number);
    a_number = d(a_number);
    a_number = e(a_number);
    y = a_number;
  }

  int y;
};

5 'callable things', all of which meet the C++20 invocable concept, but are of different types (Yes, d can only be called as if it has one parameter from the context of a method of D or a derived class, but that's the example context I've used!).

And then if you use if constexpr, that will also impact how you interpret the program:
C++
template<uint32_t Offset, uint32_t Size>
struct bit_field_t {
  :         :
// Other methods
  :         :
   auto get_value(uint32_t from_field) {
      if constexpr (Size == 1) {
         // Return a Boolean if Size == 1
         return (field & (1<<Offset)) == (1<<Offset);
      }
      // Return a uint32_t if Size != 1
      else {
         return (field>>Offset) & ((1<<Size)-1);
      }
   }
};

In this case, the value of the template parameter Size (which forms part of the type of instances of bit_field_t) determines the return type of the method get_value.

Unfortunately, that's just the way it is with strongly/statically typed languages unless you have some pretty strict rules about only using things that have already been declared, so you always have the necessary type information to tag nodes in your AST/code dom. For example, I think OCaml has a single pass parser, and it requires you to explicitly denote recursion, whether direct or indirect, a classic case where languages aren't always sure if the thing you're referring to has already been defined. (note that these functions are strongly typed, but OCaml has a sophisticated type inference engine that doesn't need (but will accept) explicit type annotations to derive types):
OCaml
let rec fac (n:int): int = 
    match n with
    | 1 -> 1
    | x -> x * fac x

(* even and odd are inferred to have type int -> int *)
let rec even n =
    match n with
    | 0 -> true
    | x -> odd (x-1)
  and odd n =
    match n with
    | 0 -> false
    | x -> even (x-1)
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

GeneralRe: Quick C# quiz Pin
Gerry Schmitz2-Dec-19 5:31
mveGerry Schmitz2-Dec-19 5:31 
GeneralRe: Quick C# quiz Pin
honey the codewitch2-Dec-19 5:33
mvahoney the codewitch2-Dec-19 5:33 
GeneralRe: Quick C# quiz Pin
zezba90002-Dec-19 8:35
zezba90002-Dec-19 8:35 
GeneralRe: Quick C# quiz Pin
honey the codewitch2-Dec-19 13:16
mvahoney the codewitch2-Dec-19 13:16 
GeneralRe: Quick C# quiz Pin
zezba90002-Dec-19 14:05
zezba90002-Dec-19 14:05 
GeneralRe: Quick C# quiz Pin
honey the codewitch2-Dec-19 14:12
mvahoney the codewitch2-Dec-19 14:12 
GeneralRe: Quick C# quiz Pin
zezba90002-Dec-19 14:42
zezba90002-Dec-19 14:42 
GeneralRe: Quick C# quiz Pin
honey the codewitch2-Dec-19 14:46
mvahoney the codewitch2-Dec-19 14:46 
GeneralRe: Quick C# quiz Pin
Member 140926054-Dec-19 21:33
Member 140926054-Dec-19 21:33 
GeneralRe: Quick C# quiz Pin
honey the codewitch4-Dec-19 21:37
mvahoney the codewitch4-Dec-19 21:37 
GeneralHomo Hackabilis ? Pin
BillWoodruff29-Nov-19 3:37
professionalBillWoodruff29-Nov-19 3:37 
AnswerRe: Homo Hackabilis ? Pin
lopatir29-Nov-19 3:54
lopatir29-Nov-19 3:54 
GeneralRe: Homo Hackabilis ? Pin
Maximilien29-Nov-19 4:00
Maximilien29-Nov-19 4:00 
GeneralRe: Homo Hackabilis ? Pin
CodeWraith29-Nov-19 4:10
CodeWraith29-Nov-19 4:10 
GeneralRe: Homo Hackabilis ? Pin
Maximilien29-Nov-19 4:22
Maximilien29-Nov-19 4:22 
GeneralRe: Homo Hackabilis ? Pin
Eddy Vluggen29-Nov-19 7:19
professionalEddy Vluggen29-Nov-19 7:19 
GeneralRe: Homo Hackabilis ? Pin
BillWoodruff29-Nov-19 19:28
professionalBillWoodruff29-Nov-19 19:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.