Random question about languages

Started by Xaron, June 24, 2018, 19:19:35

Previous topic - Next topic

col

QuoteIn our company I sometimes see hierarchies of 10 derived classes.
Thats just crazy  :o
omg  :P
https://github.com/davecamp

"When you observe the world through social media, you lose your faith in it."

Henri

#31
@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

Steve Elliott

Win11 64Gb 12th Gen Intel i9 12900K 3.2Ghz Nvidia RTX 3070Ti 8Gb
Win11 16Gb 12th Gen Intel i5 12450H 2Ghz Nvidia RTX 2050 8Gb
Win11  Pro 8Gb Celeron Intel UHD Graphics 600
Win10/Linux Mint 16Gb 4th Gen Intel i5 4570 3.2GHz, Nvidia GeForce GTX 1050 2Gb
macOS 32Gb Apple M2Max
pi5 8Gb
Spectrum Next 2Mb

col

#33
QuoteHow 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

Function something()
    x:Int = 10
    x:Int            ' compiler error... duplicate definition
    x = 20          ' assignment
EndFunction
https://github.com/davecamp

"When you observe the world through social media, you lose your faith in it."

Xaron

Haha yes guys I know... That inheritance has come due to "historical reasons". Our codebase is huge.

So would something like


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:


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

MikeHart

#35
I would rather see it like this:
Function something()   
  Int x = 10   
  '....   
  x = 20
EndFunction

But then, this isn't BASIC style.

Xaron

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?

col

@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
https://github.com/davecamp

"When you observe the world through social media, you lose your faith in it."

Xaron

Those template error messages can be "fun".  ;D