Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 521 522 [523] 524 525 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 883240 times)

Antsan

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7830 on: September 15, 2015, 04:29:19 am »

I think if that works it's called weak typing. I have no idea how that evaluates to 70, unless
Code: [Select]
("3"..5)
evaluates to 35 somehow, which seems just off for what I suppose is an operator called '..'. I don't know Lua, but I'd expect this to evaluate to something like
Code: [Select]
(6, 8, 10)

Python and Common Lisp have dynamic strong typing. This means that Variables don't have types (unless they have been specifically declared to have types) but values do.
Forth, for instance, has weak typing. Duck typing seems like excessive overloading with dynamic strong types.
Logged
Taste my Paci-Fist

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7831 on: September 15, 2015, 04:34:42 am »

The reason I liked it in Python is that it wouldn't flip a shit when trying to concatenate strings with various other things. And when using a strong-typed language, "forgot the type declaration" is usually the first stupid mistake I make.
This is one reason to perhaps learn a typed language before learning a non-typed language. Like learning to drive a manual before an automatic.

I sometimes accidentally write "for(int i=0; i< n; i++)" in Javascript because I'm so used to putting the type in, rather than your problem.

"The interpreter does everything for you" is both a blessing and a curse for learning to program.

C# has static typing and doesn't have a problem with adding things to strings.

"One" + 1 = "One1"

It's pretty easy to add that one to C++ too with overloads. It's better than complete duck typing because you know that anything is cast string if one of the things is cast to string, at compile time. "3" + 3 = "33" (or 3+"3" = "33") in all cases then. You can even overload the equality operator, so if you really want to compare strings and other variables for equality in the representations "if("33" == 33)" you can do that consistently. It will also tell you if there's no defined operator for a pair of types at compile time, so you don't need to run a program to work out whether it will fuck up.

For compile-time duck-typing, we have templates in C++. You just define a function or class which takes a type as a variable. Type "T" is the standard go-to, but the name can be anything. Then, the compiler works out whether the inputs make sense for you, and asks for clarification if they do not. You can in fact take any object, call it's "quack" function, and the compiler will work out whether there is a "quack" function for the thing you passed, spitting out an error if it's not a thing that "quacks". I'd prefer this to stupid run-time duck typing, which is defined as cross-your-fingers and run the program, relying on runtime errors to tell you that you made a mistake. What if the mistake was in a seldom-called branch of code? Compile-time checking would have prevented it ever being deployed with that error.
« Last Edit: September 15, 2015, 04:55:23 am by Reelya »
Logged

Orange Wizard

  • Bay Watcher
  • mou ii yo
    • View Profile
    • S M U G
Re: if self.isCoder(): post() #Programming Thread
« Reply #7832 on: September 15, 2015, 04:37:01 am »

I think if that works it's called weak typing. I have no idea how that evaluates to 70, unless
Code: [Select]
("3"..5)
evaluates to 35 somehow, which seems just off for what I suppose is an operator called '..'.
Lua's .. operator is for string concatenation, and converts any ints involved to strings. So "3" .. 5 = "35", and "35" * 2 = 70.
Logged
Please don't shitpost, it lowers the quality of discourse
Hard science is like a sword, and soft science is like fear. You can use both to equally powerful results, but even if your opponent disbelieve your stabs, they will still die.

Antsan

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7833 on: September 15, 2015, 05:02:12 am »

Thanks! That makes sense. '..' usually is used for ranges, as far as I can tell, thus the confusion.
Logged
Taste my Paci-Fist

Arx

  • Bay Watcher
  • Iron within, iron without.
    • View Profile
    • Art!
Re: if self.isCoder(): post() #Programming Thread
« Reply #7834 on: September 15, 2015, 08:15:03 am »

IDE question: is NetBeans' C++ plugin any good? I'm using CodeBlocks at the moment, but I've become used to NetBeans' super convenience, and there's no reason in my particular case not to use it (unless the C++ plugin is terrible).
Logged

I am on Discord as Arx#2415.
Hail to the mind of man! / Fire in the sky
I've been waiting for you / On this day we die.

LoSboccacc

  • Bay Watcher
  • Σὺν Ἀθηνᾷ καὶ χεῖρα κίνει
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7835 on: September 15, 2015, 09:32:58 am »

I used it 2+ years ago and it sucked compared to CodeBlock. Anyway why not Visual Studio Express? Are you on a specific env?
Logged

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7836 on: September 15, 2015, 09:35:16 am »

If going Visual Studio, I'd recommend VS Community 2013, and to skip the 2015 version for now. There was some bullshit in the 2015 one relating to having to periodically renew your subscription with microsoft.com every 30 days, and half the time the subscription service doesn't work, and just totally locks you out of the program so you can't even use it as a text editor.

So, I had to rollback to VS2013 because of this bullshit making VS2015 completely non-functional thus wasting a pile of time when I has assignments due the next day.
« Last Edit: September 15, 2015, 09:37:54 am by Reelya »
Logged

Arx

  • Bay Watcher
  • Iron within, iron without.
    • View Profile
    • Art!
Re: if self.isCoder(): post() #Programming Thread
« Reply #7837 on: September 15, 2015, 09:37:48 am »

I used it 2+ years ago and it sucked compared to CodeBlock.

That's not my experience, but that can probably be chalked up to opinion.

Anyway why not Visual Studio Express?

I don't want to download 'up to 6GB' to test an IDE, mostly.
Logged

I am on Discord as Arx#2415.
Hail to the mind of man! / Fire in the sky
I've been waiting for you / On this day we die.

Bumber

  • Bay Watcher
  • REMOVE KOBOLD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7838 on: September 15, 2015, 09:41:07 am »

C# has static typing and doesn't have a problem with adding things to strings.

"One" + 1 = "One1"
Huh. I would've expected a C language to add the ␁ (start of header) ASCII character without the use of a conversion function.
« Last Edit: September 15, 2015, 09:44:29 am by Bumber »
Logged
Reading his name would trigger it. Thinking of him would trigger it. No other circumstances would trigger it- it was strictly related to the concept of Bill Clinton entering the conscious mind.

THE xTROLL FUR SOCKx RUSE WAS A........... DISTACTION        the carp HAVE the wagon

A wizard has turned you into a wagon. This was inevitable (Y/y)?

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7839 on: September 15, 2015, 09:50:24 am »

standard c-style languages has never had anything like that.

Code: [Select]
char *string ="12345"
string = string + 1;
printf(string);

What will this print?

12346. Wrong
123451. Wrong
12345(plus ascii char 1). Wrong
2345. Correct

That's because the variable "string" is nothing but an alias for a 32-bit value which holds a memory pointer. Whether what it points at is a valid string is not something your program knows about. Adding one to that just increments the memory pointer by one, it doesn't call any special string-processing code, because there is no string-processing code in c unless it's added as an additional library.

So, the plus operator for standard c-style strings just changes where you're starting the string in memory. It's not a defined string operation, and there is no concatenation system unless you pull that in from one of the libraries. Because of that, when they created c++ and C#'s string classes they were free to interpret "+" however they wanted to.
« Last Edit: September 15, 2015, 10:10:15 am by Reelya »
Logged

Bumber

  • Bay Watcher
  • REMOVE KOBOLD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7840 on: September 15, 2015, 10:08:05 am »

standard c-style languages has never had anything like that.
Not in C, but C++'s std::string lets you concatenate either type of string with operator+. I don't suspect it would let you add an integer to a string by default, however. You'd want to use streams, sprintf, or the non-standard itoa to convert if you wanted the number, else a type cast if you wanted ASCII.
« Last Edit: September 15, 2015, 10:25:13 am by Bumber »
Logged
Reading his name would trigger it. Thinking of him would trigger it. No other circumstances would trigger it- it was strictly related to the concept of Bill Clinton entering the conscious mind.

THE xTROLL FUR SOCKx RUSE WAS A........... DISTACTION        the carp HAVE the wagon

A wizard has turned you into a wagon. This was inevitable (Y/y)?

Bauglir

  • Bay Watcher
  • Let us make Good
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7841 on: September 15, 2015, 10:38:27 am »

That's why you have generic functions, where you can say that "This input can be any type as long as it supports these functions"

So if you try to pass in a variable of a type that doesn't support draw(), get_position(), and get_size(), you'll get an error right there.
Yeah I guess looking into it a bit more you can have static duck typing that will do that. So you're right, dynamic typing is a different thing. So with dynamic typing, you'll get that error at runtime; with static typing, you'll get the error at compile time. Off the top of my head, the best example of why you'd want that is an eval() function that evaluates a string passed into it as code. Security issues aside, there's no way to know for sure at compile-time what the hell the string is going to do, so you can't exactly allocate memory for any variables that get declared in it. Evidently there is a way to handle this in statically typed languages using some advanced algebra types or something but I don't understand the words Wikipedia uses to describe the situation so I can't speak to that. Sounds like a pain in the ass though!
Logged
In the days when Sussman was a novice, Minsky once came to him as he sat hacking at the PDP-6.
“What are you doing?”, asked Minsky. “I am training a randomly wired neural net to play Tic-Tac-Toe” Sussman replied. “Why is the net wired randomly?”, asked Minsky. “I do not want it to have any preconceptions of how to play”, Sussman said.
Minsky then shut his eyes. “Why do you close your eyes?”, Sussman asked his teacher.
“So that the room will be empty.”
At that moment, Sussman was enlightened.

itisnotlogical

  • Bay Watcher
  • might be dat boi
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7842 on: September 15, 2015, 12:46:11 pm »

I'm making my biannual attempt to learn C/C++, and something just struck me: nobody writing C++ uses whole words as symbols. It's always fsptrs, grglflrgns and igglgiggls. Don't get me wrong, I can't stand it when another language's documentation has something like this:

Code: (Pretty sure I've actually seen this in a Java tut somewhere) [Select]
FileInputStream fileInputStream = new FileInputStream(DirectoryToFileForFileInputStream);

... but I'd rather have that than the opposite problem. D:
Logged
This game is Curtain Fire Shooting Game.
Girls do their best now and are preparing. Please watch warmly until it is ready.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7843 on: September 15, 2015, 01:40:38 pm »

That's really C legacy stuff from the 1960s and 1970s. But memory constraints were pretty nasty back then so they had reasons...

The C++ stuff added later isn't all that bad in comparision.

For example, here's c's stdio:

http://www.cplusplus.com/reference/cstdio/

vs c++'s iostream:

http://www.cplusplus.com/reference/iostream/

They do the same thing basically, but look at the difference between the list of functions you need to know about. That's possible because in c++ everything in the libraries is an object, and they can handle operations through methods which are part of each object, and handle different types of data through automatic type overloading. Those two concepts didn't exist in the original c language, so they had to make differently named functions for every single combination of action and data type.
« Last Edit: September 15, 2015, 01:51:43 pm by Reelya »
Logged

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7844 on: September 15, 2015, 06:06:02 pm »

This is a better representation of iostream than your link, Reelya.
Logged
Pages: 1 ... 521 522 [523] 524 525 ... 796