Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 592 593 [594] 595 596 ... 796

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

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #8895 on: February 01, 2016, 11:37:36 pm »

Java in data structures class makes me so frustrated :( so much needless typing...

Can I have my C# please?
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8896 on: February 02, 2016, 06:45:50 am »

Define 'needless'?
Logged
Sigtext

It has been determined that Trump is an average unladen swallow travelling northbound at his maximum sustainable speed of -3 Obama-cubits per second in the middle of a class 3 hurricane.

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #8897 on: February 02, 2016, 08:00:47 am »

For one, the "one public class per file" rule struck me as being arbitrary.

The only real example of needless boilerplate I can think of is this:

ClassName thing = new ClassName();

C# lets you do this:

var thing = new ClassName();

It's a big help for long classnames, plus it's actually still statically typed since "var" can be inferred to be ClassName at compiletime, plus if you want a different polymorphic type just say so.

It would be much better if the IDE I was using was better at intellisense, but alas.

edit:

I also don't like that they didn't overload the String class's [] operator, have to use charAt() instead. And no == overloading, gotta use .equals()...
« Last Edit: February 02, 2016, 08:18:24 am by Skyrunner »
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8898 on: February 02, 2016, 09:15:41 am »

Eh?
You can declare more than one class per file IIRC.

But it's a good thing to do in any case.
Logged
Sigtext

It has been determined that Trump is an average unladen swallow travelling northbound at his maximum sustainable speed of -3 Obama-cubits per second in the middle of a class 3 hurricane.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8899 on: February 02, 2016, 09:27:56 am »

The only real example of needless boilerplate I can think of is this:

ClassName thing = new ClassName();

That seems a bit trivial in the typing sense. A quick ctrl-c/ctrl-v gets that almost as quick as typing "var" would. Plus it's much less flexible: if you want to split up declaration and initialization then you have additional work to do to get rid of the "var" keyword. In other words, savings 0.1 seconds of typing but makes things a pain in the ass later for maintenance.
« Last Edit: February 02, 2016, 09:37:19 am by Reelya »
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #8900 on: February 02, 2016, 09:30:39 am »

ClassName thing = new ClassName();

Isn't "needless" ... because of polymorphism. In c++, the "new" keyword can assign any type to the pointer variable on the left, so the two types don't necessarily have to be the same, and you'd want to be able to specify that.

Not comparing to C++ but C#, which seems to do perfectly fine at deducing the type from the variable. if you want a base class, you would have to specify the base class, but the rest of the time you can use var and everything goes fine.
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8901 on: February 02, 2016, 09:42:19 am »

var is sloppy - would not recommend for any serious usages. Saving 0.1 seconds of typing isn't work extra headaches later on working out what types things actually are.

Sure it can make code "cleaner" by removing context, but that doesn't necessarily translate to good maintainable code.
« Last Edit: February 02, 2016, 09:44:25 am by Reelya »
Logged

Rose

  • Bay Watcher
  • Resident Elf
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8902 on: February 02, 2016, 09:51:39 am »

I often use var at first, when quickly typing something out, and then go back and replace it.
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #8903 on: February 02, 2016, 09:54:37 am »

In the end, it's mostly my IDE's fault for not doing intellisense properly :v
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

i2amroy

  • Bay Watcher
  • Cats, ruling the world one dwarf at a time
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8904 on: February 02, 2016, 01:03:22 pm »

What I find is the best place for var/auto is in loops. In that case not being able to see instantly what type it is doesn't hurt you quite as much because the important part is already non-visible because it's linked to the object that you are iterating through. And it provides some benefits in that if you ever need to update the type of the object that you are iterating (for example going from an array to a vector, or some such, or making the objects stored inside of it go from a single object to a bundled struct) then it can save you a lot on refactoring every single mention of it.

This is not to say, of course, that you should be abusing the auto keyword everywhere, or even in every loop. It just goes to show that, IMO, there are places where it certainly is useful in providing enough benefits to outweigh the fact that the type of an object isn't immediately apparent at the first glance. (It's also useful for cases where you have very complex data structures holding the things you care about, like a dictionary of vectors of arrays or something similar, since it can eliminate a huge amount of extra typing in those cases with all of the "::iterator" stuff you need to throw on the end).
Logged
Quote from: PTTG
It would be brutally difficult and probably won't work. In other words, it's absolutely dwarven!
Cataclysm: Dark Days Ahead - A fun zombie survival rougelike that I'm dev-ing for.

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8905 on: February 02, 2016, 03:10:01 pm »

The only real example of needless boilerplate I can think of is this:

ClassName thing = new ClassName();

That seems a bit trivial in the typing sense. A quick ctrl-c/ctrl-v gets that almost as quick as typing "var" would. Plus it's much less flexible: if you want to split up declaration and initialization then you have additional work to do to get rid of the "var" keyword. In other words, savings 0.1 seconds of typing but makes things a pain in the ass later for maintenance.
Er, I didn't say that.
Logged
Sigtext

It has been determined that Trump is an average unladen swallow travelling northbound at his maximum sustainable speed of -3 Obama-cubits per second in the middle of a class 3 hurricane.

Vattic

  • Bay Watcher
  • bibo ergo sum
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8906 on: February 02, 2016, 04:28:34 pm »

I am failing to understand a bit of found code that takes the aspect ratio and area of a rectangle and returns the width and height. I wondered if anyone else might be able to explain. I suspect this is a basic maths fail on my part.

Spoiler (click to show/hide)
« Last Edit: February 02, 2016, 04:31:14 pm by Vattic »
Logged
6 out of 7 dwarves aren't Happy.
How To Generate Small Islands

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8907 on: February 02, 2016, 04:31:29 pm »

Well, how do you calculate aspect ratio?
Logged
Sigtext

It has been determined that Trump is an average unladen swallow travelling northbound at his maximum sustainable speed of -3 Obama-cubits per second in the middle of a class 3 hurricane.

Vattic

  • Bay Watcher
  • bibo ergo sum
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8908 on: February 02, 2016, 04:33:05 pm »

width / height.
Logged
6 out of 7 dwarves aren't Happy.
How To Generate Small Islands

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8909 on: February 02, 2016, 04:34:12 pm »

Well there's your answer.  I think.
« Last Edit: February 02, 2016, 04:37:56 pm by TheBiggerFish »
Logged
Sigtext

It has been determined that Trump is an average unladen swallow travelling northbound at his maximum sustainable speed of -3 Obama-cubits per second in the middle of a class 3 hurricane.
Pages: 1 ... 592 593 [594] 595 596 ... 796