Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • December 02, 2016, 08:26:30 PM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Strangest language feature  (Read 2338 times)

Eóin

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 1,401
    • View Profile
    • Donate to Member
Strangest language feature
« on: December 09, 2010, 11:13:58 AM »
Fantastic question (thread?) from over on stack overflow. Plenty of things in there I never knew about. For example:

In JavaScript:
'5' + 3 gives '53'
Whereas
'5' - 3 gives 2

From reddit originally


Deozaan

  • Charter Member
  • Joined in 2006
  • ***
  • Points: 1
  • Posts: 7,713
    • View Profile
    • The Blog of Deozaan
    • Read more about this member.
    • Donate to Member
Re: Strangest language feature
« Reply #1 on: December 09, 2010, 11:50:19 AM »
That was fun to read through.


MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,275
    • View Profile
    • Miles Ahead Software
    • Donate to Member
Re: Strangest language feature
« Reply #2 on: December 09, 2010, 12:07:18 PM »
ahk can't be too far behind with this usage:

If 0 < 1
{
MsgBox, 64, DummyApp Usage, Usage: DummyApp params
ExitApp
}

To anyone coming from another programming language, the If statement should always be true, like "while 1" ... but not so!! :)

Renegade

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 13,220
  • Tell me something you don't know...
    • View Profile
    • Renegade Minds
    • Donate to Member
Re: Strangest language feature
« Reply #3 on: December 10, 2010, 06:11:21 AM »
I liked this (Algol):

Code: C [Select]
  1. int a[3] = { 1, 2, 3 };
  2. int i = 1;
  3.  
  4. void f(int j)
  5. {
  6.     int k;
  7.     k = j;  // k = 2
  8.     i = 0;
  9.     k = j;  // k = 1 (!?!)    
  10. }
  11.  
  12. int main()
  13. {
  14.     f(a[i]);
  15. }

At first glance, it looks hosed, but reading through starting at main() it makes perfect sense. My question then is... Sanity? Are you there? :P :D

Thanks for that link! Some very cool stuff in there.
Slow Down Music - Where I commit thought crimes...

Freedom is the right to be wrong, not the right to do wrong. - John Diefenbaker

f0dder

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 9,029
  • [Well, THAT escalated quickly!]
    • View Profile
    • f0dder's place
    • Read more about this member.
    • Donate to Member
Re: Strangest language feature
« Reply #4 on: December 10, 2010, 06:14:27 AM »
Renegade: ugh, everything is passed by reference?
- carpe noctem

Eóin

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 1,401
    • View Profile
    • Donate to Member
Re: Strangest language feature
« Reply #5 on: December 10, 2010, 06:55:48 AM »
Even if passed by ref that still doesn't make much sense :D

f0dder

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 9,029
  • [Well, THAT escalated quickly!]
    • View Profile
    • f0dder's place
    • Read more about this member.
    • Donate to Member
Re: Strangest language feature
« Reply #6 on: December 10, 2010, 09:05:49 AM »
Even if passed by ref that still doesn't make much sense :D
No, it would have to be... copied by reference? :P - very strange behavior for what I would expectto be a value type.
- carpe noctem