Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 524 525 [526] 527 528 ... 796

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

itisnotlogical

  • Bay Watcher
  • might be dat boi
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7875 on: September 20, 2015, 03:48:26 pm »

I could have sworn an if statement with single-equals wouldn't compile in C#. Is there an instance where that would be correct?
Logged
This game is Curtain Fire Shooting Game.
Girls do their best now and are preparing. Please watch warmly until it is ready.

Dutrius

  • Bay Watcher
  • No longer extremely unavailable!
    • View Profile
    • Arcanus Technica
Re: if self.isCoder(): post() #Programming Thread
« Reply #7876 on: September 20, 2015, 03:50:03 pm »

It always throws a compiler error in VS, anyway.
Logged
No longer extremely unavailable!
Sig text
ArcTech: Incursus. On hold indefinitely.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7877 on: September 20, 2015, 04:09:31 pm »

In Unity I had a C# single equals bug the other day, which ended up being in the final build because it was a rarely-triggered situation, and only caused some anomolies, not a crash or anything.

But there's also portability. If you get into the habit of pretending it's not a problem because VS/C# will pick it up, you end up with sloppy coding habits when you transfer your skills to Unity/C# or C++ or Javascript and the like.

And there's also the situation that just relying on VS to pick up that you used a single-equals accidentally does not address the issue of being able to refactor your code quickly, or centralize error checking.

For example, you can put bounds-checking in a Set operator, which filters out bad inputs in one place, or you can put an assert in there instead, which triggers a halt if you put the wrong values in (which you can fix at compile time, then avoid the overhead of bounds-checking during runtime). So, you can see wrappers around internal variables allow you to add or remove error-checking mechanisms as needed, giving you better debugging during development, but which can all be pulled out virtually instantly for a high-performance build later on.
« Last Edit: September 20, 2015, 04:18:40 pm by Reelya »
Logged

miauw62

  • Bay Watcher
  • Every time you get ahead / it's just another hit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7878 on: September 20, 2015, 04:29:49 pm »

I think C# getters and setters don't even have to be explicitly called, you can just use your variable normally. Not sure, though.
Logged

Quote from: NW_Kohaku
they wouldn't be able to tell the difference between the raving confessions of a mass murdering cannibal from a recipe to bake a pie.
Knowing Belgium, everyone will vote for themselves out of mistrust for anyone else, and some kind of weird direct democracy coalition will need to be formed from 11 million or so individuals.

i2amroy

  • Bay Watcher
  • Cats, ruling the world one dwarf at a time
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7879 on: September 20, 2015, 04:48:37 pm »

But there's also portability. If you get into the habit of pretending it's not a problem because VS/C# will pick it up, you end up with sloppy coding habits when you transfer your skills to Unity/C# or C++ or Javascript and the like.
Pretty much every IDE I've used for C++ or Java will flag that as a "are you sure about this?" type of warning. It won't outright come and crash on compilation, but it will look furtively in that direction when you compile.

As for the original question, I do think it's important to point out that you should not be just automatically creating a getter and a setter for every single variable (though many people get in the habit of automatically doing that, and some IDE's will even do it automatically for you). The major point of getters and setters is to allow you to keep various parts of the code separate, allowing for each thing to be present in it's own little bubble and only interacting in controlled ways. As such you should try to avoid adding getters and setters unless that particular bit of code actually needs to be able to get and set, thus maintaining that level of code separation in your code design methodology. (This isn't, of course, intended to say that you should avoid all getters, and setters, just that your first step after adding a new variable shouldn't be to automatically add getters and setters, because at that point you honestly might as well just make the variable public and be done with it).
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.

i2amroy

  • Bay Watcher
  • Cats, ruling the world one dwarf at a time
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7880 on: September 22, 2015, 01:54:49 am »

Double Post, but nobody else has posted here and it's been a day and it's an unrelated thing dang-nabit! :P

So I'm taking a class in web design/html and such... and ugh! I'm starting to see one of the reasons why the internet is so broken and people have such problems with basic web design, html and its set of related languages feel like they were written by a drunken monkey. There's no good reason why I should have to constantly fight with the default formatting every time I want to do something; if that is happening it's probably a sign that your default setting isn't a good choice.

It's like if I want to do something simple like move a button from its (stupid) default location to a more sensible one, do something simple like make the columns in that table all the same width while still automatically scaling to match page size down to a minimum, or whatever. Easy ways to do those things? Nope! That one requires a workaround, and that requires a 20-line javascript header addition, and that requires this hacky thing where you reset the line priority of everything to -1 because the default 0 causes these certain page elements to randomly move around for no apparently reason. And if that wasn't confusing enough it seems like half of the hacks and workarounds were (rightly) depreciated in html5... but they never addressed the base problems that the workarounds and hacks were intended to fix!

We're only 2 weeks into this course and already it's making me consider gouging out my own eyes so I don't have to deal with the horridity of the language... and we still have another 13 solid weeks to go! :'(
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.

Reelya

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


make the columns in that table all the same width while still automatically scaling to match page size down to a minimum, or whatever. Easy ways to do those things? Nope! That one requires a workaround, and that requires a 20-line javascript header addition
Are you sure you need javascript to scale columns in a table? Have you tried using percentages rather than pixels to specify the sizes?

This will give you a 4 column table which always matches the window, and the columns will always be 25% each:

Code: [Select]
<table style="width:100%;" border="1">
<tr>
<td style="width:25%">1</td>
<td style="width:25%">2</td>
<td style="width:25%">3</td>
<td style="width:25%">4</td>
</tr>
</table>

If you want it to scale up/down, you set the width of the table element to be some absolute amount of pixels instead of the percentage:

Code: [Select]
<table style="width:800px" border="1">
<tr>
<td style="width:25%">1</td>
<td style="width:25%">2</td>
<td style="width:25%">3</td>
<td style="width:25%">4</td>
</tr>
</table>

One important rule: always assume your teacher actually sucks at the language they're teaching. This is often the case. Never assume what the teacher says is the best way to do things.
« Last Edit: September 22, 2015, 02:29:45 am by Reelya »
Logged

i2amroy

  • Bay Watcher
  • Cats, ruling the world one dwarf at a time
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7882 on: September 22, 2015, 02:26:27 am »

Those answers weren't really 1-1 to the stated problems. It was more a general list of problems with a couple of workarounds for various other (not necessarily matching) problems I've encountered. :P One of the problems I did run into (might have been something to do with buttons or forms, I can't really remember right now) did have as the "preferred solution" to it on StackOverflow was the addition of this rather large javascript addition to do a simple little change that honestly should have just been the default setting for that particular element type. :P

Honestly most of the problems I've been running into the horrible hacks to fix them have been the things espoused by the community at large through sites like StackOverflow, not necessarily my professor's personal opinions.
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.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7883 on: September 22, 2015, 02:33:42 am »

Well the main thing you mentioned needing the hack for was for evenly-spacing table cells. Which is what I covered. Actually, I think just specifying "width:100%" in the table's style, by itself should be enough to get all columns to be equal and scale up/down properly. When you set the tables dimension either in pixels or percentages, then the cells automatically get a share of that, unless you specify a particular column, e.g. "width:50%" on the first column would give that one 50% of the size and the rest would get an equal-share of the remaining table size.

Spoiler (click to show/hide)
Also, if you're using Javascript just to get buttons where you want on the screen you're probably doing something wrong. Javascript only works that way by editing the HTML and CSS attributes after all. I've never needed a separate script to move buttons where I want, and you certainly don't see code like that if you peek at existing websites with "view source".
« Last Edit: September 22, 2015, 02:53:32 am by Reelya »
Logged

i2amroy

  • Bay Watcher
  • Cats, ruling the world one dwarf at a time
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7884 on: September 22, 2015, 03:13:53 am »

My big point is that in so many cases the defaults of so many things are far from what they should be intuitively. Sure I can muck around with a variety of tags with every single little thing to get them to look the way that I want them to, but I shouldn't have to. I mean when was the last time that you saw a "submit" button at the top of a form? I personally can't ever remember a time, but IIRC right now html5 just grabs any submit buttons by default (even if they are in a table or something similar) and sticks them at the top of the form unless you specifically tell it not to. You can prevent it with a bit of work, of course, but the point is that you shouldn't have to, because the default is nonsensical. Or take evenly spaced table columns. I don't know about you, but I see a lot more tables with columns evenly spaced across their total area than those that are non-evenly spaced. Yet the default uses a weird stretching algorithm, despite the fact that it looks horrible 95% of the times when it gets used. Just a simple default change to evenly spaced unless you specify it to not be that way would do loads towards cleaning table formatting up.

And many of these defaults don't even have easy "one line" fixes; often the smallest fixes tend to require at least 3-4 lines (well, 3-4 nicely formatted human readable lines) in your CSS file to fix up their look like their defaults should already be, and some of them can take many more than that to get them looking nice.

For example (assuming I remember correctly), the best way to do something such as put an image with a link (where just the image was clickable, not the entire block) that was centered in the middle of your page in html5 took about 7 lines to do, and involved the idea of creating a new centered div class and then treating the image as a text-like block so that you could align it with the text-align styling in said class, and then adjusting the margins on top of that because it won't work right unless you do. When you are purposely treating one type of data as another simply so that you can use the formatting tools that should rightfully be available to the first data type already, that's usually a good sign that there's a problem in your language of choice. :P It would be like if for some reason you couldn't convert int values to a string, so instead what you would do is cast the int to a float, then tell the stringstream to display 0 decimal places. It's just not something that makes good logical sense!

Nothing is a big problem, or that difficult to fix, but it's just the sheer number of problems wears down on your over time. With modern capabilities just leaving things as the basics should be able to get me something that at least looks halfway decent, and only requires me fiddling with it if I want a specific format or I want to do something special. It shouldn't leave me looking at a web page that has randomly shuffled around or hidden some of the elements, jumbled and stretched things for no apparent reason, and overall looks somewhat similar to if a dictionary vomited all over the page.

I guess I'd just much prefer something more programatic that takes the approach of "here's something nice looking, but if you do anything crazy than you might need to cover yourself or it will break" instead of the markup approach of "here's this piece of crap, but we guarantee that it will never break no matter what you stuff into it! Oh you are just using it for everyday, basic stuff? Too bad, because we have to catch everything it'll still look like crap unless you add a lot more work to make it look nice". A "I'd rather have to tell you not to help me on the rare occasion I need to do something more unique" approach rather than a "I want you to do the absolute bare minimum to help unless I specifically tell you otherwise just on the rare chance that whatever you would do would cause problems".
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.

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #7885 on: September 22, 2015, 03:53:03 am »

Well, the problem is your preferred default of evenly spaced table columns is only preferred for you. For me, I that that columns of varying sizes seems more common a use case than a table with all columns the same width--just look at the table layout for General Discussion!

Multiply that by everything and that's why it's hard to have a good default case.

Since everyone has their own idea of what they want their page to do, clearly the best answer is to make almost everything configurable.

(I'm not really a fan of CSS though, just playing devil's advocate. There is a reason none of my webapps have fancy formatting...)
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

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7886 on: September 22, 2015, 07:38:07 am »

The nonsense on web design is absolutely the reason that at my job I Just hand things off to the interface guy without doing any design work.

"Hah, you didn't even try, did you?"

"Nope, it would take me 5 times as long and it would need changing anyway.  All of the forms and client side code are implemented, it just needs styling."

HTML does feel like it was designed by a drunken monkey, and that's partly because it was devised ages ago before anyone knew what we needed, and has to live with its heritage despite improvements lately.  A huge one that's still a problem, despite a proposed solution, is the HTML5 video tag.  It was created specifically to rid us of the need of Flash based video players, but because they didn't specify at least one mandatory format and codec, every major browser implements different ones and you still need Flash and JavaScript or 3 different video files in different formats.

I'm not sure what all can be done about HTML and CSS being a supreme pain in the butt though.  It's trying to effectively give you a way to make high quality images that are dynamically rendered on different view screens and in a format that expects content to flow indefinitely downward if it needs to.  That's... tricky to design something not terrible for.

I really do hate working with it though.  So glad I only have to deal with JavaScript for the most part.

Now I'm wondering if anyone has tried creating a higher level language that compiles down to HTML and CSS, but is more intuitive... for all its problems, ExtJS actually did have some pretty nice layout managers that worked like I wished HTML and CSS did.  Something like that maybe, where you can define viewports that take up the full screen, elements that vertically center things, easily created columns that fill the remaining space in an element, and so on.
Logged
Through pain, I find wisdom.

Antsan

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7887 on: September 22, 2015, 07:48:57 am »

Quote
Now I'm wondering if anyone has tried creating a higher level language that compiles down to HTML and CSS, but is more intuitive...
There are libraries for Common Lisp who are exactly that. I never used one of them, but they seem to be much easier to use than HTML and they also allow you to use all of Common Lisp to calculate your page as it should be.
Logged
Taste my Paci-Fist

3man75

  • Bay Watcher
  • I will fire this rocket
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7888 on: September 22, 2015, 09:35:47 am »

Anyone know a tip for if and if else statements? I find that I can get my geometry calculator to work for Circle (other functions not done yet) I can make it so it gives me the right answer. But I'm not sure how to stop the user from giving me a negative number.

BTW I'm doing this in C++ but I can't exactly find the answer to my question in if statements part of cplusplus.com.


Spoiler: Code (click to show/hide)
« Last Edit: September 22, 2015, 09:38:13 am by 3man75 »
Logged

RulerOfNothing

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7889 on: September 22, 2015, 10:10:24 am »

I would do something like:
Code: [Select]
do
{
cout << "Please enter the radius of the circle (radius must not be negative): " << endl;
cin >> radiousC;
}
while(radiousC<0);
Also you can't have cin input to endl (as endl is actually implemented as a function)
Logged
Pages: 1 ... 524 525 [526] 527 528 ... 796