Ooops
February 25, 2020, 03:51:55 PM

Author Topic: Random question about languages  (Read 3162 times)

Offline col

  • Sr. Member
  • ****
  • Posts: 441
Re: Random question about languages
« Reply #30 on: June 27, 2018, 08:03:26 PM »
Quote
In our company I sometimes see hierarchies of 10 derived classes.
Thats just crazy  :o
omg  :P
To be is to be perceived.

https://github.com/davecamp

Offline Henri

  • Full Member
  • ***
  • Posts: 220
Re: Random question about languages
« Reply #31 on: June 27, 2018, 08:42:04 PM »
@Local

Comrate GW had a valid point though: How would you distinguish between declaration and assignment ? In C assignment is recognized with = (edit. whoops, got assignments and comparisons mixed up. You see already confusing :-)  . Ambiguity is the number one cause of bugs in this world.


@Inheritance
I remember reading somewhere that usually, if you find yourself inheriting more than 2 times, you are probably doing it wrong.


-Henri
- Got 01100011 problems, but the bit ain't 00000001

Offline Steve Elliott

  • Hero Member
  • *****
  • Posts: 2241
  • elgol developer
Re: Random question about languages
« Reply #32 on: June 27, 2018, 09:52:36 PM »
10 derived classes! PMSL.  :o
Windows 10, 64-bit, 16Gb RAM, CPU Intel i5, 3.2 GHz, Nvidia GeForce GTX 1050 (2Gb).
MacOS Catalina, 64-bit, 8Gb RAM, CPU Intel i5, 2.3 Ghz, Intel Iris Plus Graphics 640 1536 MB.
Linux Mint 19.3, 64-bit, 16Gb RAM, CPU Intel i5, 3.2 GHz, Nvidia GeForce GTX 1050 (2Gb).
C64, Raspberry pi 3 and 4.

Offline col

  • Sr. Member
  • ****
  • Posts: 441
Re: Random question about languages
« Reply #33 on: June 27, 2018, 09:53:04 PM »
Quote
How would you distinguish between declaration and assignment ? In C assignment is recognized with ==
In C assignment is recognised with = and equality ( compare equal ) is recognised with ==.

C/C++ are different from what most folks that are used to BASIC languages are used to in that you can declare a variable ( which gives the compiler a brief description of a variable or function ) and you can also define it separately. You can also declare and define at the same time to. When you declare a 'thing' ( variable, function, function pointer, struct, class etc) you would just give the type and name of it. When you define that 'thing' you fill in all of the missing pieces ( such as the meat and guts of a function or class ). You can't use a 'thing' until it is also has a  definition somewhere - Even more confusing is that the code will probably compile, at least up to the point of linking which is when the compiler looks for the definition. If you encounter the 'undefined reference to blah::blah()' then you're missing the definition, ie the actual function itself ( which would usually, but not always, be in a lib file somewhere ) when you link with static libraries.

Oops I kinda wondered off there, and there is also much more to say about it, and with examples, but I don't mean to go off on a pointless tangent :p

For a BASIC-like language you *could* have it that when you define a variable and define its type along with that variable then that is a new definition, no need for Local etc.
It's also up to the language designer if they require you to put the type before of after the variable name.

So for a new variable you would have
Code: [Select]
Function something()
    x:Int = 10
    x:Int            ' compiler error... duplicate definition
    x = 20          ' assignment
EndFunction
To be is to be perceived.

https://github.com/davecamp

Offline Xaron

  • Sr. Member
  • ****
  • Posts: 276
Re: Random question about languages
« Reply #34 on: June 28, 2018, 08:25:15 AM »
Haha yes guys I know... That inheritance has come due to "historical reasons". Our codebase is huge.

So would something like

Code: [Select]
Function something()
    x:Int = 10
    x:Int            ' compiler error... duplicate definition
    x = 20          ' assignment
EndFunction

really ok? Or is it somehow confusing for someone?

Is it "easier" to have:

Code: [Select]
Function something()
    Local x:Int = 10
    Local x:Int    ' compiler error... duplicate definition
    x = 20          ' assignment
EndFunction

Offline MikeHart

  • Hero Member
  • *****
  • Posts: 641
  • Cerberus-X developer
    • Cerberus X
Re: Random question about languages
« Reply #35 on: June 28, 2018, 08:40:51 AM »
I would rather see it like this:
Code: [Select]
Function something()   
  Int x = 10   
  '....   
  x = 20
EndFunction
But then, this isn't BASIC style.

Offline Xaron

  • Sr. Member
  • ****
  • Posts: 276
Re: Random question about languages
« Reply #36 on: June 28, 2018, 09:10:51 AM »
Indeed, I somehow would prefer it that way as well as I think it has better readability... But yes, it's not classic Basic style. Question is, does it have to?

Offline col

  • Sr. Member
  • ****
  • Posts: 441
Re: Random question about languages
« Reply #37 on: June 28, 2018, 10:57:28 AM »
@Henri,
I know what you mean. The amount of times I've discovered a bug due to missing the  '=' key for the second one in '==' and ending up with just '=' is ridiculous. C is bordering 'bearable' but C++ with its STL has turned into a hideous ugly language. I posted a little while ago about how I had a syntax error in 1 place which threw up over 500 errors :D
To be is to be perceived.

https://github.com/davecamp

Offline Xaron

  • Sr. Member
  • ****
  • Posts: 276
Re: Random question about languages
« Reply #38 on: June 28, 2018, 11:52:21 AM »
Those template error messages can be "fun".  ;D

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal