last day (208 days later) » 
13:00 - 17:0017:00 - 00:00

1:54 PM
@EBrown AngularJS is more like the straight A* student, and jQuery the dropout
 
@DanPantry I can agree with that.
$(".main-datalist-results > *:not(#results-template)").each(function (i) {
    if ($(".purchase-quantity", this).eq(0).val() > 0) {
        if (ds.length > 1)
            ds = ds + ","
        ds = ds + "{\\\"ItemNumber\\\":\\\"" + $(".item-number", this).eq(0).html() + "\\\",\\\"Quantity\\\":" + $(".purchase-quantity", this).eq(0).val() + "}";
    }
});
I hate how that looks, which is why I hate jQuery.
There has to be better ways to write that.
 
Agreed.
 
That doesn't really look like a jQuery problem.
In the same way that I could write code similar to that in ASP MVC C# and not blame it on ASP MVC
 
Well, I'm not great with JavaScript that's for sure, but still. jQuery just makes it such a pain in the arse to work with, I never have time to learn best-practices.
 
you could rewrite that to use objects and then JSON.stringify at the end
 
1:57 PM
I hate JavaScript, because I hate UI work.
I prefer backend Framework work.
 
I'm sorry but the only ugly part of that code is the bit that's not jQuery
 
@EBrown I think that jQuery makes it easier
 
I don't see how you can blame that on jQuery or JavaScript in general
That's just someone not used to JavaScript/not someone who likes JavaScript using JavaScript
 
Which is why I took about a week and developed a much more stable framework for this website.
 
I hate UI as well, but never used JS for it. Still hate JS.
 
1:58 PM
but I am with you on hating UI work....lol and writing content....get me a writer for that
 
@DanPantry Regardless of the inner workings, and my lack of skill in JavaScript, this whole line ($(".main-datalist-results > *:not(#results-template)").each(function (i) {) pisses me off.
 
Doing some UI stuff isn't that bad, getting paid for googling aroundf or a bit and playing with the layout until it looks nice
 
$('.js-datalist-results>li').each(function() { ... });
That code reeks of just bad design in the first place
I don't see how any of that has anything to do with JavaScript and everything to do with just being an ugly solution to a badly thought out problem. and that's not JavaScript's fault
 
@DanPantry It is, though. JavaScript should have better, easier ways to do simple things like that.
 
@EBrown it does have simpler ways. I just listed them
 
2:01 PM
$('.js-datalist-results>li').each(function() { ... }); is no simpler...lol
 
I don't get what's wrong with it
 
It's ugly.
 
But somewhat fast
 
@EBrown it eremoves the heavy coupling of the CSS selector.
If you really want to use plain JS you can do this:
const results = document.querySelector('.js-datalist-results>li');
 
The problem is that I have to ignore the first row.
 
2:02 PM
results.forEach(function(element) { .. })
 
.js-datalist-results>li is a slow selector. .js-datalist-results li is way faster
 
@IsmaelMiguel it's not the selector he suggested, it's just his original selector had an > in it
 
@DanPantry const in Javascript?
 
@EBrown how else would you suggest that?
@IsmaelMiguel ES6 is a thing, friend
 
(Which is the the *:not(#results-template) bit.)
 
2:03 PM
const and let are now things that exist
 
@DanPantry Too soon.... Too soon
 
Also, we have to support older browsers.
 
@IsmaelMiguel transpilers also exist
 
Too soon for that...
 
You can use a transpiler for backwards compatibility.
 
2:03 PM
ES6 is still a baby
 
hey guys this is getting pretty specific, and the conversation is getting pretty long, can we move it to another chat room more specified for this conversation?
 
@Malachi The only specificity is the language and the version, in my opinion
 
ES6 is new, yes, but transpilers transpile to ES5, which is most definitely not new and can be used in lots of browsers all the way back to IE8, which is also not new.
 
@IsmaelMiguel that's cool, just beginning to be a big conversation, which is okay, but it can flood business out of chat quickly. I enjoy the conversation and would love to follow the chat in another room
 
@Malachi Can you make the room? If the others approve
 
2:06 PM
@Malachi I'm done with my anti-JavaScript rant anyway.
 
im happy to take this to another room
 
Ping me the room later
 
although @IsmaelMiguel you should bear in mind that this main conversation is because @EBrown does not like javascript, rather than asking for improvements on the code he posted :P
 
what should I call it?
 
@Malachi javascript vs reasonable people
4
 
2:07 PM
lol
 
JavaScript sucks Donkey Balls
Or is that too blunt?
 
Too graphic
 
Damn
 
JavaScript sucks 2d donkey balls
javascript.png
 
Nope, still uses too many graphics
Jsucks
Done
 
2:08 PM
how about Javascript Libraries
 
@Malachi lol
 
Fine by me
 
so... Malachi, go use your room owner privileges
you should be able to create the room from the move messages dialog..
 
You should make it something cunning.
 
Greetings

 Web Development

Everything Web
 
2:12 PM
Monking
 
(not mine)
So, what was wrong with that code?
 
It's just ugly, man.
 
The mismannered way you have to manipulate JavaScript to server your needs is unpleasant.
A good language doesn't require the programmer to work around it.
 
Code for reference
$(".main-datalist-results > *:not(#results-template)").each(function (i) {
    if ($(".purchase-quantity", this).eq(0).val() > 0) {
        if (ds.length > 1)
            ds = ds + ","
        ds = ds + "{\\\"ItemNumber\\\":\\\"" + $(".item-number", this).eq(0).html() + "\\\",\\\"Quantity\\\":" + $(".purchase-quantity", this).eq(0).val() + "}";
    }
});
The only ugly things I see here are:
 
2:13 PM
Javascript was made to be changed to the way you wish
 
77 messages moved from The 2nd Monitor
 
.main-datalist-results > *:not(#results-template) really?
 
Has to be.
 
Who made that selector?
 
- Selector (not Javascript)
- The ugly JSON escaping (bad JavaScript)
- Unused i
- uncached `.purchase-quantity` value
the biggest problem here is you're mixing DOM access with business logic
 
2:14 PM
That selector is awful
God!
 
That was a copy/paste from another project here.
 
OH GOD!
 
I don't do JavaScript.
 
Whoever wrote that JS was bad at JS
that is not representative of javascript - at all
 
thank you, guys.
 
2:15 PM
I already told you they were bad at VB.NET.
 
that JSON object is just.. hilarious
 
And css
 
and web dev, in general
 
That JSON object gets posted back to the server.
 
what browser did this have to support?
 
2:15 PM
That selector will give me nightmares!
 
            if (ds.length > 2) {
                $('#addToCartModal').modal('show');
                $.ajax({
                    type: "POST",
                    url: "/Entry.aspx/AddToCart",
                    data: '{Items: "' + ds + '"}',
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: OnAddToCartSuccess,
                    failure: function (response) {
                        //alert(response.d);
                    }
 
o.O
THAT JSON IS BROKEN!
 
I commented out the failure alert because it's not necessary.
 
IT IS INVALID!
 
"what's single responsibility principle" - the developer who wrote this code
 
2:16 PM
No it's not.
 
It is
 
It is.
 
function addItemsToCart() {
var ds = "[";

$(".main-datalist-results > *:not(#results-template)").each(function (i) {
if ($(".purchase-quantity", this).eq(0).val() > 0) {
if (ds.length > 1)
ds = ds + ","
ds = ds + "{\\\"ItemNumber\\\":\\\"" + $(".item-number", this).eq(0).html() + "\\\",\\\"Quantity\\\":" + $(".purchase-quantity", this).eq(0).val() + "}";
}
});

ds = ds + "]";

if (ds.length > 2) {
$('#addToCartModal').modal('show');
$.ajax({
type: "POST",
url: "/Entry.aspx/AddToCart",
data: '{Items: "' + ds + '"}',
 
\\\" becomes \" which is invalid json
 
'{Items: "' + ds + '"}' should be '{"Items":"' + ds + '"}'
 
2:17 PM
You tell that to ASP.NET.
 
"{\\\"ItemNumber\\\":\\\"" + $(".item-number", this).eq(0).html() + "\\\",\\\"Quantity\\\":" + $(".purchase-quantity", this).eq(0).val() + "}"
this becomes
i cant even
i dont even want to write this out
 
Yes, I know that bit, technically in the markup it's wrong, but if you omit the \\\" bit, and turn it into \" as expected, ASP.NET refuses to recognize it because somehow that \" is broken down to ", which is treated as a literal.
I had the exact same thought you do, but it doesn't work like that with ASP.NET.
 
the eval'd value becomes
'{"ItemNumber":"0","Quantity":1}'
I replaced first $ call with 0 and second with 1
 
When it hits the server, correct.
 
so I suppose it is valid
the issue i have with that code is
why the hell is he writing theo bject by hand
 
2:20 PM
.main-datalist-results > *:not(#results-template) --> is that this hurts me deep in my soul!
 
Because he (and just as well, I) don't trust JavaScript.
 
@IsmaelMiguel i know, right? could have just done .datalist__results .datalist__result
 
.main-datalist-results :not(#results-template) --> This is better
 
@EBrown that's stupid.
I'm sorry but that is really stupid
There is no reason to not 'trust' javascript
the browser vendors
 
@DanPantry XSS
 
2:21 PM
except IE
 
We only support IE.
 
@IsmaelMiguel XSS isn't going to be fixed by kludging a JSON string like that
@EBrown what version?
 
@DanPantry I know
 
So don't bring vendor arguments in here, because we are required to only support IE from 7 through 11.
Now, that particular setup only has to support 9/10/11.
 
our office has to support ie9 for a legacy project and angular in it's entirey works there
 
2:21 PM
The 7/8 versions see a completely different site.
 
and angular uses JSON.stringify extensively
 
They don't get any fancy JavaScript.
 
JSON.stringify isn't fancy javascript, its built-in.
 
I know that, but then I have to create objects.
And add items to them.
And I just don't have time for that.
 
....what?
 
2:23 PM
I would rather work on the core site functionality than mess around with JavaScript stuff that I really hate using anyway.
 
@DanPantry It's a very important part.
 
I'm the only person in this company who knows even a little JavaScript, and I just don't enjoy it.
And I don't have time for it.
 
I'm sorry did you just say you would rather hack together nasty string concatenation than use javascript the way it was meant to be used?
 
And it doesn't create any nasty bugs I cannot solve.
I didn't really hack it together, I Copy/Pasted it from other stuff.
And it works.
It just, bloody, works.
 
sure, it does
as long as you aren't a maintainer
if you're going to complain about something being ugly and then refuse to do it a way that actually works
 
2:24 PM
As soon as I start messing with extra, complex, stuff, it can fail.
 
you lose all right to complain it's ugly
 
I wouldn't even know where to start with it, because JavaScript is so piss-poorly documented and standardized, that there's no easy way to find out what to do.
And just as well, the jQuery is required. We cannot remove or replace it (bootstrap, not my choice.)
I cannot swap it out for Angular, because our UI dev does not want to use it.
Honestly, the only reason this is here is because the owner wanted us to "eliminate page refreshes."
 
var ds = [];
$('.datalist-results *:not(#results-template)').each(function() {
  if($('.purchase-quantity', this).eq(0).val(0) > 0) {
    ds.push({ ItemNumber: ..., Quantity: ... });
  }
});
var json = JSON.stringify(ds);
// send json to server
and that's without removing the awful selector, without changing each to map and caching .purchase-quantity
var items = $('.datalist-results *:not(#results-template)').map(function(item) {
  return { ItemNumber: ..., Quantity: ... };
});
var json = JSON.stringify(items);
I presume the check for .purchase-quantity is to check whether or not the quantity is greater than 0.
 
I do that server side.
 
You also do it client side, apparently
if ($(".purchase-quantity", this).eq(0).val() > 0) {
that's why I omitted it
 
2:29 PM
Yeah, but I really don't need to.
 
yeah, again - that's why I omitted it
 
It's only there because the server was having JSON issues early on.
I assume the var items means that items will be lower-case in the JSON?
 
No, var items is a variable declaration.
It's no different from, say, int items
(except it's not an int but an array)
 
Right, but what about telling the server that it's the Items parameter?
Or were you only intending to use it as the array of items?>
 
function addItemsToCart(items, onSuccess, onFailure) {
  var payload = { Items: items };
  var json = JSON.stringify(payload);
  $.ajax({
    type: 'post',
    url: '/entry.aspx/AddToCart',
    data: json,
    contentType: 'application/json; charset=utf-8',
    dataType: 'json',
    success: onSuccess,
    failure: onFailure
  });
}

function updateCart() {
  var cartItems = $('.main-datalist-results > *:not(#results-template)').map(function(element) {
    var item = {
      ItemNumber: $('.item-number', element).val(),
my stab at it (which includes your items parameter)
it's still not perfect but it's a darn sight better than what you had
 
2:34 PM
Damnit Visual Studio. Such a pain in the arse.
 
lol
I can't guarantee it will work or even do the same thing, I haven't tested it
it should be just a refactor but I don't really use jquery so -shrug-
 
"Oh I see you selected text, let me just erase your clipboard."
 
i have to use the vim plugin to make vs bearable
 
Just use Notepad++
 
@IsmaelMiguel notepad++ won't compile c# code and typescript and integrate with TFS
 
2:35 PM
@IsmaelMiguel Notepad++ isn't colouring my JS all of a sudden...
 
all of which, unfortunately, my company requires
otherwise I use vim (or sublimetext)
 
At least they're using some form of source control.
 
@DanPantry You can provide it a compiler, and it will compile the code
 
@IsmaelMiguel yes, but it won't manage my C# sln/proj files
 
@Mast That's weird. Are you sure you didn't disabled highlighting?
@DanPantry True... :/
 
2:36 PM
@Mast honestly, given the amount of a PITA TFS is I'd rather use no source control over TFS
Also doesnt help other developers do monolothic commits and don't use branches
 
microsofts bastardized attempt at SVN
 
subversion, old centrallized source control
 
2:37 PM
branching model involves creating separate copies of the entire source control tree for each branch
 
I use backups
 
@IsmaelMiguel You never heard of SVN?!
 
and every commit has to be checked into the main server
 
i barely can work with Github
 
I use git
 
2:38 PM
Raise the alarm!
 
that's because you don't work on github
 
@Mast I've heard before
 
github hosts git repos
 
I've never used it or knew what it was
 
Git is good, SVN is good, just pick one. Don't use none.
 
2:38 PM
I prefer git to SVn
SVN
 
GIT > SVN
Unfortunately.
 
but im not teetotal enough to say SVN is bad
 
GIT is awesome, just a PITA to set up
 
just git suits my preference more
 
I have no idea how it would work for me
 
2:39 PM
GIT is more powerful and SVN leaves a bit to be desired.
 
it is? :S
 
Every time I set up a new project it takes me a couple of hours to figure out how.
I never got the hang of it.
 
get the command line
 
Tried both.
 
git init && touch .gitignore && git add -A && git commit -m "initial commit"
or, if you have git extras
 
2:40 PM
How would GIT work with a website?
 
touch .gitignore && git setup
 
To control it's source?
 
@IsmaelMiguel you'd store all of it's source in a git repository and then deploy it to amazon s3/whatever with a shell script
 
@IsmaelMiguel Just like with any other project.
 
should have just dumped you guys into the Nth Monitor.... LOL you guys aren't really talking about JavaScript anymore...lol it's all good
 
2:40 PM
But I don't have amazon s3
 
@IsmaelMiguel you can use anything , doesnt have to be S3
see this for example deploy script to s3
 
We are talking about a service, which partially is about Javascript
@DanPantry I use a custom server
My boss pays for it
 
@IsmaelMiguel the thing I linked is my website at cv.lambdaexpression.io
 
Well I'm still testing out @DanPantry's JavaScript rewrite of this crap.
 
@DanPantry Which creates a git repo in the local directory and adds the current files inside the current directory?
 
2:42 PM
@Mast yes
 
And besides, it would be a pain to test 1 character change
 
@IsmaelMiguel that's why you test on your local machine using a local http serverwhich points at your working directory.
or use automated tests.
 
I can't
It's a centralized service that depends on a defines structure
with over 150 websites
 
if you can't test it in isolation, well
 
@DanPantry Stickied. Gonna try it with the next project.
 
2:44 PM
@Mast Good luck, git is great but it's not easy (for newbies)
 
Using it is easy, SVN as well. Setting it up has always been my problem with it.
 
here's an example of a microservice REST program, you could look at the history to see how it developed and how I set it up. github.com/danpantry/identity
it's very basic and i haevn't finished it yet, but still
 
Alright Dan, we're about to find out if this works
 
@EBrown Nothing ever works the first time :-)
2
 
"Internal Server Error" on postback.
 
2:48 PM
@EBrown good stuff :P
 
Great.
It's because of the JSON.
 
well, Ididn't expect the client side bit to work so I am pleasantly surprised
What is it complaining about?
@IsmaelMiguel here's an example of a full-stack application hosted at champion.gg
not sure how that's deployed, though, it's only a fork
 
Oh I see, your JSON structure is not the same as it expects, methinks.
 
@EBrown it should be exactly the same 0.o
 
Not even close.
 
2:50 PM
it is exactly the same
unless the values are different
I'm not sure what .eq(0).html() does
Ah
it selects the first element from the set and then returns the html code
So the structure should be the same, its just the values that are different
 
Not even close, man.
 
expcet for the part where you for some reason post {\\\"ItemNumber\\\":\\\
 
Starts off as: "{"Items":{"0":{"ItemNumber":"","Quantity":""}
 
oh bugger
I know why
jquery's map returns an object instead of an array
because, you know, that makes sense
(it doesnt)
 
I knew there was a reason I used simplistic markup. :P
 
2:53 PM
every other map returns an array :P
and I did dsay I don't use jquery
> var items = [ { ItemNumber: "0", Quantity: "1" } ]
undefined
> var payload = { Items: items };
undefined
> JSON.stringify(payload);
'{"Items":[{"ItemNumber":"0","Quantity":"1"}]}'
>
if the map worked you'd end up with that.
 
Except that's not how it's generated.
Yeah.
I get all this extra stuff at the end.
"length":38,"prevObject":{"0":{"location":{"ancestorOrigins":{"length":0}
 
Ahhhhhh, map sets index first and element second.
 
Which are not valid.
At least, not for what the server is expecting.
 
this is literally just because of my inexperience with jQuery :P
.item-number isnt an input is it?
it's just a field
that would explain why you used .eq and .html
 
No, it's a <span>.
Yeah.
 
2:56 PM
replace updateCart with this.
function updateCart() {
  var cartItems = $('.main-datalist-results > *:not(#results-template)').map(function(_, element) {
    var item = {
      ItemNumber: $('.item-number', element).eq(0).html(),
      Quantity: $('.purchase-quantity', element).eq(0).html()
    };
    return item;
  });
  addItemsToCart(cartItems, OnAddToCartSuccess, function() {})
}
 
<tr id="results-template" class="none">
                                        <td><span class="item-number"></span>
                                            <br />
 
also, Quantity should have eq(0).val() not eq(0).html()
sorry, Im sleepy. Check out the edit I made.
 
Yeah, the debugger was complaining on return items...lol
 
it would have also complained on me passing updateCart to addItemsToCart.
 
I was replacing that manually.
 
2:58 PM
I really need to sleep lol
 
I'm still getting a context and length parameter.
 
fk jquery
If you're still here in a few hours I'll help you rewrite this completely
but I have like
 
Face it man, jQuery just doesn't work well.
I'll be here all day.
 
1 hour left in work
and there'se a lot of stuff I need to do
 
It's 1100, and I leave work at 1700.
 
3:00 PM
Yeah, that's why I avoid jQuery. My main point though is that javascript is not the problem
And javascript is not a bad language
but it CAN be written ugly/badly - just like every other language
For example - C# still has GOTO
 
Yeah, but you cannot use GOTO for a line number unless you're Jon Skeet.
 
Jon Skeet doesn't code. His code writes itself.
 
But, if you're willing to help me rewrite this, and it looks cleaner/better, I'll consider retracting some of my JavaScript hate.
Jon Skeet is the Chunk Norris of programming.
 
No problem. My rate is £20/h. Just kidding, I'll do it for free.
Just give me... 2 hours. I'll be home then.
 
Right on, I'll still be here at work.
 
3:03 PM
@DanPantry A League of Legends' website?
 
@IsmaelMiguel yes. it's written in nodejs and angular (albeit badly)
 
Oh, it is
I don't use those :/
 
The point is to show how git can be used for real websites, both static and server-hosted.
 
 
2 hours later…
4:52 PM
Hello
I am home now
 
Very nice, is it a two hour drive for you?
 
No, it's a 30 minute walk
but it's 20 minutes from leaving work until that 30 minute walk
I finish at 5pm
 
What timezone?
UTC+?
 
UTC
I think
 
Ah, I'm UTC-4 atm.
Eastern Daylight Time.
 
4:55 PM
MURIKA
im a brit so
 
*Murica
No K, just a C.
Sometimes, 'Merica
I have a few British friends.
One is from Cannock, IIRC.
 
you have another one ;-)
I live in Wales, no idea where cannock is
I'm all out of pizza and i got a 20% raise today... well... I know how to solve this
Anyway, where do you want to start?
 
Nowhere specific to me.
I can start sending JS and HTML over.
Plus I'm in maintenance mode atm. Just refactoring, cleaning and optimizing code.
So if you have any ideas of a good starting base, let me know man.
I'm all ears.
Also, now that you mention it, it's Pizza Day here at work as well.
 
Well, you know your code better than I do :)
You have pizza day at your work? I'm jealous
 
Lunch starting in 5 minutes.
Or so.
 
4:59 PM
Although getting a 20% raise today like it was nothing kinda makes up for not haing pizza day.
 
13:00 - 17:0017:00 - 00:00

  last day (208 days later) »