Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Chill Callahan
Nov 14, 2012
I think the horror is using the ViewBag that much or even at all.

Adbot
ADBOT LOVES YOU

fritz
Jul 26, 2003

nuvan posted:

That isn't XOR. This is XOR.

code:
 ^ | 0 | 1 |
------------
 0 | 0 | 1 |
 1 | 1 | 0 |
When the compared bits are different, the result is 1. When they are the same, the result is 0.
In other words, one OR the other, but NOT both. Hence, eXclusive OR, or XOR for short.

This is also why 0x(something) ^ 0x00 will remain the same, because 0x0 ^ 0x0 == 0x0 and 0x1 ^ 0x0 == 0x1

e:f;b

I like to visualize the two-argument truth functionals as a 16-long table

code:
0 0 0 0 FALSE
0 0 0 1 AND
0 0 1 0 FIRST AND NOT SECOND
0 0 1 1 FIRST
0 1 0 0  SECOND AND NOT FIRST
0 1 0 1  SECOND
0 1 1 0  XOR
0 1 1 1  OR
1 0 0 0  NOR
1 0 0 1 NOT XOR
1 0 1 0 NOT SECOND
1 0 1 1 (NOT SECOND) OR FIRST
1 1 0 0 NOT FIRST
1 1 0 1 (NOT FIRST) OR SECOND
1 1 1 0 NAND
1 1 1 1 TRUE
Where the columns correspond to input arguments of (0,0), (0,1), (1,0), (1,1) and the name is the function that's true on those given inputs. So the function that is false on (0,0) and (1,1), but true on (1,0) and (0,1) would be in row "0110" of the table, and it's called XOR.

Pretty sure this is all in Knuth somewhere. Also I can never remember what implies what in 2 4 11 and 13 but who ever uses those.

raminasi
Jan 25, 2005

a last drink with no ice

Chill Callahan posted:

I think the horror is using the ViewBag that much or even at all.

I'm leaning towards it being the lack of code tags.

Knyteguy
Jul 6, 2005

YES to love
NO to shirts


Toilet Rascal
C# code:
$("#restart-application").click(function (e) {
        showThrobber('@Html.Raw(HttpUtility.JavaScriptStringEncode(T("Admin.Header.RestartApplication.Progress").Text))');
    });
});
Kinda sorta :nws: emoticon?
:dong:

Qwertycoatl
Dec 31, 2008

Honest Thief posted:

The problem is they have a method signature setting, I guess, the flag to false to force the new logic, and yet kept the method signature as it is and the whole code. Because, I dunno. The only other place its used the flag is always true, so I dunno, either it's leftover code from whenever or..

It's not forcing the flag to false, it's setting a default value, so if a caller doesn't specify the flag it'll be false, but if they want it to be true they can set it.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

This is a dangerous thread to post in. If you're going to post a horror, you better know your poo poo!

kitten smoothie
Dec 29, 2001

Knyteguy posted:

C# code:
$("#restart-application").click(function (e) {
        showThrobber('@Html.Raw(HttpUtility.JavaScriptStringEncode(T("Admin.Header.RestartApplication.Progress").Text))');
    });
});
Kinda sorta :nws: emoticon?
:dong:

For what it's worth, the activity indicator in a browser used to be called a "throbber." Dating back to when Netscape 1.0 used a throbbing N.

Deus Rex
Mar 5, 2005

Chill Callahan posted:

I think the horror is using the ViewBag that much or even at all.

This sort of thing ain't my Bag baby!

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
Oh ViewBag is an actual Thing? I thought it was hilariously lovely naming for that particular method. My bad.

what the hell is a ViewBag?

Meat Beat Agent
Aug 5, 2007

felonious assault with a sproinging boner
A ViewBag is what they put your models in when you buy them at the data store

Honest Thief
Jan 11, 2009
I've brought shame to my (un)fabled .net skills, but it still makes no sense to me since the method is only called twice, and in both cases they explicitly set the flag.

Honest Thief fucked around with this message at 21:12 on Dec 15, 2014

nuvan
Mar 29, 2008

And the gentle call of the feral 3am "Everything is going so well you can't help but panic."

fritz posted:

I like to visualize the two-argument truth functionals as a 16-long table

code:
0 0 0 0 FALSE
0 0 0 1 AND
0 0 1 0 FIRST AND NOT SECOND
0 0 1 1 FIRST
0 1 0 0  SECOND AND NOT FIRST
0 1 0 1  SECOND
0 1 1 0  XOR
0 1 1 1  OR
1 0 0 0  NOR
1 0 0 1 NOT XOR
1 0 1 0 NOT SECOND
1 0 1 1 (NOT SECOND) OR FIRST
1 1 0 0 NOT FIRST
1 1 0 1 (NOT FIRST) OR SECOND
1 1 1 0 NAND
1 1 1 1 TRUE
Where the columns correspond to input arguments of (0,0), (0,1), (1,0), (1,1) and the name is the function that's true on those given inputs. So the function that is false on (0,0) and (1,1), but true on (1,0) and (0,1) would be in row "0110" of the table, and it's called XOR.

Pretty sure this is all in Knuth somewhere. Also I can never remember what implies what in 2 4 11 and 13 but who ever uses those.

Let's express this in boolean logic, because! (also, added the implications you mentioned [I hope I'm remembering all my logic right])


| (0,0) | (0,1) | (1,0) | (1,1) | Logical Statement
-------------------------------------------------------
|   0   |   0   |   0   |   0   | A ∧ ¬A
|   0   |   0   |   0   |   1   | A ∧ B
|   0   |   0   |   1   |   0   | A ∧ ¬B [aka ¬(A → B)]
|   0   |   0   |   1   |   1   | A
-------------------------------------------------------
|   0   |   1   |   0   |   0   | ¬A ∧ B [aka ¬(B → A)]
|   0   |   1   |   0   |   1   | B
|   0   |   1   |   1   |   0   | (A ∨ B) ∧ ¬(A ∧ B) [aka ¬(A ↔ B)]
|   0   |   1   |   1   |   1   | A ∨ B
-------------------------------------------------------
|   1   |   0   |   0   |   0   | ¬(A ∨ B)
|   1   |   0   |   0   |   1   | ¬(A ∨ B) ∨ (A ∧ B) [aka A ↔ B]
|   1   |   0   |   1   |   0   | ¬B
|   1   |   0   |   1   |   1   | A ∨ ¬B [aka B → A]
-------------------------------------------------------
|   1   |   1   |   0   |   0   | ¬A
|   1   |   1   |   0   |   1   | ¬A ∨ B [aka A → B]
|   1   |   1   |   1   |   0   | ¬(A ∧ B)
|   1   |   1   |   1   |   1   | A ∨ ¬A
-------------------------------------------------------


Would have put the logical expressions first, but it turns out that the logical-and/logical-or symbols aren't actually fixed width like everything else.

Knyteguy
Jul 6, 2005

YES to love
NO to shirts


Toilet Rascal

pokeyman posted:

what the hell is a ViewBag?

It's kind of a dynamic object container for holding whatever you want. Generally it's used for small things like ViewBag.PageTitle = "fooTitle" for a webpage title tag, but anything after the "." can be an object, so you can make ViewBag.Foo = new string[]{}, ViewBag.Bar = "", ViewBag.Baz = 1, etc. Not sure if ViewBag.Class works but that'd be coding horror territory since viewmodels work much better here. The ViewBag is automatically instantiated* with your data in the view, so you can call it by the same convention like <title>@ViewBag.PageTitle</title>

* It might be static instead of instantiated, and perhaps data is flushed every time a view is called? I've never tested.

Knyteguy fucked around with this message at 22:23 on Dec 15, 2014

nielsm
Jun 1, 2009



Knyteguy posted:

It's kind of a dynamic object container for holding whatever you want. Generally it's used for small things like ViewBag.PageTitle for a webpage title tag, but anything after the "." can be an object, so you can make ViewBag.Foo = new string[]{}, ViewBag.Bar = "", etc. Not sure if ViewBag.Class works but that'd be coding horror territory since viewmodels work much better here.

So it's a dictionary for passing stuff into templates? Except not really a dictionary because that would be too easy?

Knyteguy
Jul 6, 2005

YES to love
NO to shirts


Toilet Rascal

nielsm posted:

So it's a dictionary for passing stuff into templates? Except not really a dictionary because that would be too easy?

Basically yea. I'm not sure why they didn't use a dictionary? The syntax is a little easier for new programmers I guess. It might have a couple advantages over a normal dictionary? Maybe someone else can chime in. Here's a little more info:
http://www.codeproject.com/Articles/476967/WhatplusisplusViewData-cplusViewBagplusandplusTem

Again though sending an instantiated ViewModel for property values is generally preferred, except for small things that every page potentially will have, but is also different from every other page, like a page title. Or at least that's how we use it unless someone gets lazy.

Knyteguy fucked around with this message at 22:33 on Dec 15, 2014

fritz
Jul 26, 2003

nuvan posted:

Would have put the logical expressions first, but it turns out that the logical-and/logical-or symbols aren't actually fixed width like everything else.

"&" "|" and "~" have always been good enough for me.

raminasi
Jan 25, 2005

a last drink with no ice

Honest Thief posted:

I've brought shame to my (un)fabled .net skills, but it still makes no sense to me since the method is only called twice, and in both cases they explicitly set the flag.

If using the default argument is conceptually sensible, then refactoring it out just because it's not used Right Now is totally sane. Narrowing interfaces for the sake of narrowing them isn't often a good use of time.

dwazegek
Feb 11, 2005

WE CAN USE THIS :byodood:

nielsm posted:

So it's a dictionary for passing stuff into templates? Except not really a dictionary because that would be too easy?

It kinda sorta is a dictionary. The ViewBag and ViewData contain the same data, they just represent 2 different ways of accessing it.

ViewBag acts as a dynamic expando object (it's not only accessed dynamically, but members can also be added and removed at runtime). ViewData acts as a Dictionary<string, object>.

So ultimately the difference is just in how you access it. ViewBag.Something = "whatever" is equivalent to ViewData["Something"] = "whatever" And seeing as they refer to the same data you could do something like this:
code:
ViewBag.Foo = "bar";
ViewData["Foo"] == "bar"; // true
Basically, you just use whichever syntax makes the most sense at the time. Most people seem to prefer the ViewBag syntax, but that only easily allows for adding data and modifying existing data, so if you want to do more complex stuff, you'd use ViewData (although it's probably a horror if you need to do anything of the sort).

Knyteguy posted:

* It might be static instead of instantiated, and perhaps data is flushed every time a view is called? I've never tested.

It's instantiated per request[1] and carries over when rendering the view, and is automatically passed to partial views and display/editor templates when they're rendered. I'm not sure if the data is maintained when calling Html.RenderAction/Html.Action from within a view though.

All that said, strongly type ViewModels are definitely the way to go for most cases. I only use it when I need to pass data between partial views (or templates) and for whatever reason I can't use a model.


[1] Strictly speaking this isn't true, but it's true enough :v:

dwazegek fucked around with this message at 01:29 on Dec 16, 2014

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
Cool thanks for the info you viewbags!

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

Honest Thief posted:

I've found classes commented whole and kept around for what I guess passes as stashing.

This really grinds my gears and is something I delete with prejudice when encountered.

Karate Bastard
Jul 31, 2007

Soiled Meat

pokeyman posted:

Cool thanks for the info you viewbags!

I believe the proper term is array of butthandles.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Wheany posted:

This really grinds my gears and is something I delete with prejudice when encountered.

I've failed people in code reviews for doing this.

karms
Jan 22, 2006

by Nyc_Tattoo
Yam Slacker

Ithaqua posted:

I've failed people in code reviews for doing this.

How would that even work? Do they need to do pushups or run around like a chicken? Have to do the dishes?

You might be shocked to hear I've never seen a code review. :shobon:

Hiowf
Jun 28, 2013

We don't do .DOC in my cave.

KARMA! posted:

How would that even work? Do they need to do pushups or run around like a chicken? Have to do the dishes?

You might be shocked to hear I've never seen a code review. :shobon:

You reject the code, which means the patch/branch won't get merged into the main repo, without further changes or fixes.

I 100% apply the same policy. Having obsolete commented out code is basically saying you don't know how version control works.

Flobbster
Feb 17, 2005

"Cadet Kirk, after the way you cheated on the Kobayashi Maru test I oughta punch you in tha face!"
Was getting FileNotFoundExceptions out of nowhere that I tracked down to a method that looked something like this:

code:
private String getCacheFileName(String prefix, String text) {
    return prefix + ":" + text;
}
What is text, you might ask? Well, it's the input to a text-to-speech synthesizer! So it's whatever the gently caress text you want the thing to read aloud. Like, I don't know, an arbitrary string of characters sent to you by someone else. Nope, let's not hash or sanitize it, let's just treat that thing as a file path and call it a day! I only managed to hit this because the message I was trying to read just happened to have a slash in it.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Flobbster posted:

Was getting FileNotFoundExceptions out of nowhere that I tracked down to a method that looked something like this:

code:
private String getCacheFileName(String prefix, String text) {
    return prefix + ":" + text;
}
What is text, you might ask? Well, it's the input to a text-to-speech synthesizer! So it's whatever the gently caress text you want the thing to read aloud. Like, I don't know, an arbitrary string of characters sent to you by someone else. Nope, let's not hash or sanitize it, let's just treat that thing as a file path and call it a day! I only managed to hit this because the message I was trying to read just happened to have a slash in it.

What is even the purpose of caching the input?

kitten smoothie
Dec 29, 2001

Ithaqua posted:

What is even the purpose of caching the input?

I assumed the TTS software was generating an audio file, and this was deriving a filename for that.

speng31b
May 8, 2010

Skuto posted:

You reject the code, which means the patch/branch won't get merged into the main repo, without further changes or fixes.

I 100% apply the same policy. Having obsolete commented out code is basically saying you don't know how version control works.

Unless the commented out code represents another approach to something and still may be useful for reference/future usage, in which case a simple "// leaving this here for reference XXX" is a nice alternative to digging through revision history. Leaving whole defunct classes is a bit extreme but not totally without basis.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

speng31b posted:

Unless the commented out code represents another approach to something and still may be useful for reference/future usage, in which case a simple "// leaving this here for reference XXX" is a nice alternative to digging through revision history. Leaving whole defunct classes is a bit extreme but not totally without basis.

You're wrong, but I'm sure you're still a pretty nice person.

If you want to write a doc then write a doc and link it from a comment. "still may be useful" is not nearly a high enough bar to take up precious understanding/scanning effort for code. (You usually have to read all of such a comment to understand whether it's relevant to what you're doing, in my experience, and I always wonder if I'm supposed to update it for refactorings and such.)

speng31b
May 8, 2010

Subjunctive posted:

You're wrong, but I'm sure you're still a pretty nice person.

If you want to write a doc then write a doc and link it from a comment. "still may be useful" is not nearly a high enough bar to take up precious understanding/scanning effort for code. (You usually have to read all of such a comment to understand whether it's relevant to what you're doing, in my experience, and I always wonder if I'm supposed to update it for refactorings and such.)

Yeah I'm a pretty nice person. I guess I mostly just find this useful when a feature is under active development. If the code was stable and I was done with it, I wouldn't commit my changes and leave the comment there forever.

Take for instance, I've half-finished a feature and my coworker has to pick it up while I'm on vacation. I might leave chunks of functionality commented out until the unit/feature was at least somewhat complete. Not as a permanent addition to the code to leave future maintainers guessing forever.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

speng31b posted:

Yeah I'm a pretty nice person. I guess I mostly just find this useful when a feature is under active development. If the code was stable and I was done with it, I wouldn't commit my changes and leave the comment there forever.

Take for instance, I've half-finished a feature and my coworker has to pick it up while I'm on vacation. I might leave chunks of functionality commented out until the unit/feature was at least somewhat complete. Not as a permanent addition to the code to leave future maintainers guessing forever.

Sounds like you want a feature branch?

speng31b
May 8, 2010

Subjunctive posted:

Sounds like you want a feature branch?

Yeah, am I allowed to leave commented out code in commits to a feature branch?

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

speng31b posted:

Yeah, am I allowed to leave commented out code in commits to a feature branch?

No, just leave the code in its interim state for your co-worker to pick up.

raminasi
Jan 25, 2005

a last drink with no ice

Subjunctive posted:

Sounds like you want a feature branch?

The specific thing desired is to have two chunks of code effectively side-by-side. Comparing "current" to "old" using your source control system is pretty easy, but just commenting one out is even easier.

speng31b
May 8, 2010

Subjunctive posted:

No, just leave the code in its interim state for your co-worker to pick up.

I think that somewhere on a sliding scale between between leaving entire dead units to haunt all future maintainers and relentlessly pruning all potentially impractical comments from a feature that's a work in progress there may be a compromise that isn't a horror?

Sorry I didn't mean to phrase that as a question. Please don't flunk me on my code review or make mean commit comments about me as you passive aggressively clean up my code with pure style commits to my feature branch.

Chuu
Sep 11, 2004

Grimey Drawer
I'm super guilty about commenting out chunks of code and checking it in while I'm doing the most basic integration testing, but it gets cleaned up before the branch gets merged or forked.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

GrumpyDoctor posted:

The specific thing desired is to have two chunks of code effectively side-by-side. Comparing "current" to "old" using your source control system is pretty easy, but just commenting one out is even easier.

Honestly I'd prefer looking at it in source control where I can see the exact differences annotated with the commit messages that introduced those changes Staring at a completely rewritten bit of code and trying to divine which differences are relevant and which are just cosmetic isn't my idea of a good time.

TheresaJayne
Jul 1, 2011

Skuto posted:

You reject the code, which means the patch/branch won't get merged into the main repo, without further changes or fixes.

I 100% apply the same policy. Having obsolete commented out code is basically saying you don't know how version control works.

My first exposure to a crucible review was not too bad, a couple of typos and a missing reference number that was it. Until i was included in another persons review as a reviewer:

OMG... he was ripped a new one with over 20 defects and being ripped apart for the way he did his solution.
I got off easy.

JawnV6
Jul 4, 2004

So hot ...

speng31b posted:

a feature that's a work in progress

Please don't flunk me on my code review .

Yeah we've got a half dozen developers with nothing better to do but yank your keyboard away at an arbitrary point in the process that you had no choice in selecting, not even a warning. That's totally a situation that happens all the time and appropriate for a code review. I've failed someone for being in Insert mode and using the arrow keys to navigate.

Adbot
ADBOT LOVES YOU

EAT THE EGGS RICOLA
May 29, 2008

return0 posted:

I used to work at this company where another team had a product and the web API for it would return 200 with a status/error string even in the presence of client or server errors, I asked why they didn't return 4xx/5xx as appropriate and they gave some long implausible sounding reason I can't remember.

oh cool you used to work with everyone else on my current project

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply