Click here to Skip to main content
14,449,221 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 5:25
mvahoney the codewitch30-Nov-19 5:25 
GeneralRe: Quick C# quiz Pin
Sander Rossel30-Nov-19 5:35
professionalSander Rossel30-Nov-19 5:35 
GeneralRe: Quick C# quiz Pin
honey the codewitch30-Nov-19 5:39
mvahoney the codewitch30-Nov-19 5:39 
GeneralRe: Quick C# quiz Pin
PIEBALDconsult30-Nov-19 12:01
professionalPIEBALDconsult30-Nov-19 12:01 
GeneralRe: Quick C# quiz Pin
Stuart Dootson2-Dec-19 0:22
professionalStuart Dootson2-Dec-19 0:22 
GeneralRe: Quick C# quiz Pin
honey the codewitch2-Dec-19 4:16
mvahoney the codewitch2-Dec-19 4:16 
GeneralRe: Quick C# quiz Pin
Member 128375641-Dec-19 23:08
MemberMember 128375641-Dec-19 23:08 
GeneralRe: Quick C# quiz Pin
Stuart Dootson2-Dec-19 0:16
professionalStuart Dootson2-Dec-19 0:16 
I have a suspicion that C++ is equally reliant (possibly more so when you get templates involved) on type information
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:
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):
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 6:31
mveGerry Schmitz2-Dec-19 6:31 
GeneralRe: Quick C# quiz Pin
honey the codewitch2-Dec-19 6:33
mvahoney the codewitch2-Dec-19 6:33 
GeneralRe: Quick C# quiz Pin
zezba90002-Dec-19 9:35
Memberzezba90002-Dec-19 9:35 
GeneralRe: Quick C# quiz Pin
honey the codewitch2-Dec-19 14:16
mvahoney the codewitch2-Dec-19 14:16 
GeneralRe: Quick C# quiz Pin
zezba90002-Dec-19 15:05
Memberzezba90002-Dec-19 15:05 
GeneralRe: Quick C# quiz Pin
honey the codewitch2-Dec-19 15:12
mvahoney the codewitch2-Dec-19 15:12 
GeneralRe: Quick C# quiz Pin
zezba90002-Dec-19 15:42
Memberzezba90002-Dec-19 15:42 
GeneralRe: Quick C# quiz Pin
honey the codewitch2-Dec-19 15:46
mvahoney the codewitch2-Dec-19 15:46 
GeneralRe: Quick C# quiz Pin
Member 140926054-Dec-19 22:33
MemberMember 140926054-Dec-19 22:33 
GeneralRe: Quick C# quiz Pin
honey the codewitch4-Dec-19 22:37
mvahoney the codewitch4-Dec-19 22:37 
GeneralHomo Hackabilis ? Pin
BillWoodruff29-Nov-19 4:37
mveBillWoodruff29-Nov-19 4:37 
AnswerRe: Homo Hackabilis ? Pin
lopatir29-Nov-19 4:54
Memberlopatir29-Nov-19 4:54 
GeneralRe: Homo Hackabilis ? Pin
Maximilien29-Nov-19 5:00
MemberMaximilien29-Nov-19 5:00 
GeneralRe: Homo Hackabilis ? Pin
CodeWraith29-Nov-19 5:10
MemberCodeWraith29-Nov-19 5:10 
GeneralRe: Homo Hackabilis ? Pin
Maximilien29-Nov-19 5:22
MemberMaximilien29-Nov-19 5:22 
GeneralRe: Homo Hackabilis ? Pin
Eddy Vluggen29-Nov-19 8:19
professionalEddy Vluggen29-Nov-19 8:19 
GeneralRe: Homo Hackabilis ? Pin
BillWoodruff29-Nov-19 20:28
mveBillWoodruff29-Nov-19 20: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.