|
GenJerDan wrote: think my Notepad is set to UNICODE So mine is set to ANSI, but it still doesn't fix the characters. Tried it with all four possible txt formats in Notepad.
I used to paste stuff in Notepad to remove all the silly characters and then one day it stopped working as expected. Notepad++ also started behaving in the same fashion which leads me to believe it is something system level.
Haven't been able to figure out what changed and I'm still dealing with it. Ended up writing a little JS applet which replaces and sanitizes whatever I paste into it.
|
|
|
|
|
Or when you copy and paste and it includes line numbers
|
|
|
|
|
I do not know how they came up with 50 years exactly, but it is funny...
Celebrating 50 years of Kids Coding[^]
Skipper: We'll fix it.
Alex: Fix it? How you gonna fix this?
Skipper: Grit, spit and a whole lotta duct tape.
|
|
|
|
|
'aint that cute: now they're all grown up and complaining about javascript.
|
|
|
|
|
Nice,
The last one you can do with 5 components - even though par is 6.
Brent
|
|
|
|
|
|
In all fairness, I think I know why JavaScript can be such a pain to learn. It seems mainly due to piss-poor over complicated explanations online using different terminology than the rest of the world. I just came across another site doing just that. Since someone needs to stand up for JavaScript on CP and right some wrongs I submit to y'all a proper explanation of what was trying to be explained on this site that shall remain nameless.
One of the age old confusions with JavaScript has been dealing with the this keyword. It's actually pretty simple to understand, provided you find someone who isn't trying to act smart by over complicating crap. If you've ever found yourself wondering why things aren't working the way you'd expect from a different language, well here's the real explanation of it without the hype.
Given this code...
var fruit = 'Orange';
window.fruit = 'Apple';
function explainThis () {
alert(fruit + ' ' + this.fruit);
}
explainThis();
var stuff = new explainThis(); In JavaScript this is simply the context of the current object. Calling something as a function doesn't create a new object in scope, but new ing that sucker up does. That's all there is to it. Forget about the kiddies online trying to make this sound more complicated than it is.
If this was bugging you, then I hope it helps. I just felt the need to show JavaScript some love since it really is a nifty language. You may now return back to your normal lounging.
Jeremy Falcon
|
|
|
|
|
I think Javascript is such a PITA to learn because:
1) my bias to what I expect. I experience this with Python as well. Anything from differently named functions for string manipulation to the whole abortion called the DOM.
2) too many strings. $("#foo")
3) too many things hard to type. Shift-$. Shift paren. Shift quote. Shift pound. Unshift. The rest of the identifier. Shift quote. Shift close parent. Unshift. Dot. etc...
4) string function name or function or property? $("#foo").val(); vs. event.args.innerText vs. (jqxWidgets example) $("#menu").jqxMenu("close");
5) Standards hell: For example, single quote or double quote: $("#menu").jqxMenu('close');
6) Insane (or is that inane) document traversal:
var parentItemText = $($($("#projectTree1").jqxTree('getSelectedItem').parentElement).children("div")[1]).text();
7) Closure madness (ok, once you get familiar with the syntax, yeah, it makes sense):
myLayout.registerComponent('Output', function (container, componentState) {
container.getElement().html($("#buildOutputContainer").html().replace("buildOutput", "buildOutput1"));
container.on("resize", (function (c) {
var ct = c;
return function () {
$("#buildOutput1").jqxTextArea({ width: ct.width + "px", height: ct.height + "px" });
};
})(container));
});
8) div hell. OK, not related to Javascript
9) framework hell. Too many, too complicated, too annoying, too idiocentric.
10) Untestable. Except by trying it manually. Yeah, I've tried a variety of test frameworks, even tried writing my own. They all suck.
Should I go on?
These are all barriers to:
1) Really grocking Javascript. For example, I just discovered this cool way to eliminate the stupidity of all these strings for acquiring elements by ID or "class" name:
id = new Proxy({},
{
get: function (target, prop) {
return function () { return $("#" + prop); };
}
});
Usage: id.menubar().jqxMenu({ width: 600, height: 30 }); instead of this crap: $("#menubar").jqxMenu({ width: 600, height: 30 });
Should I do that or not? Performance penalty vs. readability? Is it more readable? Will it confuse someone who has to maintain the code.
Versus, say, a server-side replacement like !menubar.jqxMenu...
Yet again another kludge that requires that you know something totally outside of pure Javascript to understand what the Javascript is doing.
2) (barriers, remember?) Not just copying and pasting all over the place. I have to force myself to create general purpose methods, even one liners, because they improve readability, but require a ton of typing to get there. Example:
function getSelectedListBoxId(listBoxName) {
return $('#' + listBoxName).jqxListBox('getSelectedItem').value;
}
function getProjectId() {
return getSelectedListBoxId("lbProjects");
}
Why do I do this? So I can have a nice function named "getProjectId" that tells me exactly what is going on, without passing in a string and without writing the abortion that looks like this:
$('#lbProjects').jqxListBox('getSelectedItem').value;
and doesn't tell me squat about the fact that "value" is actually the ID of the item in the list box.
And since I do this for a bunch of listboxes on the page, hence the first function which is more abstract.
etc.
I hope you enjoyed this post!
modified 3-Dec-17 19:47pm.
|
|
|
|
|
Marc Clifton wrote: I hope you enjoyed this post!
Enjoyed it? Unsure, still reeling.
But it has helped me narrow down what I might learn next: It 'aint javascript.
|
|
|
|
|
Marc's just old. Don't listen to him.
Jeremy Falcon
|
|
|
|
|
Jeremy Falcon wrote: Marc's just old. Don't listen to him.
We call it wisdom. (I suffer the same affliction.)
|
|
|
|
|
Oh snap.
Jeremy Falcon
|
|
|
|
|
Jeremy Falcon wrote: Marc's just old. Don't listen to him.
That's actually what I tell my gf.
|
|
|
|
|
Jeremy Falcon
|
|
|
|
|
Marc, that's a lot of stuff to go over man. At lot of these points are mainly due to design concerns and just being old and resistant to change. Forgive me, but I'll have to skim over some of this stuff, but will address some points
Marc Clifton wrote: 1) my bias to what I expect. I experience this with Python as well. Anything from differently named functions for string manipulation to the whole abortion called the DOM. It's an object representation of what's displayed. I'm not sure how it's an abortion. About the only thing I can see with that is old skool compatiblity issues. You can blame Microsoft and Mozilla for that. They didn't give two flips about each other. But those days are gone for the most part. Life is better.
Marc Clifton wrote: 2) too many strings. $("#foo") Marc, we're professionals man. Come on.
Marc Clifton wrote: 5) Standards hell: For example, single quote or double quote: $("#menu").jqxMenu('close'); Most web languages support both. Can't blame JavaScript for that.
Marc Clifton wrote: var parentItemText = $($($("#projectTree1").jqxTree('getSelectedItem').parentElement).children("div")[1]).text(); Clearly, you're looking at code written by a 5 year old that doesn't know anything about CSS selectors or jQuery.
Marc Clifton wrote: Should I do that or not? Performance penalty vs. readability? Is it more readable? Will it confuse someone who has to maintain the code. Unless you're willing to refactor everything, then yeah that's nifty. The problem here is the design. Back in the olden days, JavaScript was tightly coupled with the DOM. Those days have changed man. I'm not saying it doesn't exist, but it's not nearly has bad as the olden days. Dealing with JScript or VBScript as no different though. It's just the way web dev was for years, and it's not really that much different in concept than XAML and people using ViewModels poorly.
Marc Clifton wrote: Why do I do this? So I can have a nice function named "getProjectId" that tells me exactly what is going on, without passing in a string and without writing the abortion that looks like this: Oh Marc, you're having fun with this aren't you?
Marc Clifton wrote: $('#lbProjects').jqxListBox('getSelectedItem').value; Now this one, I'm just gonna have to agree with. I never used jqxListbox before, but I can almost guarantee you they're trying to simulate OOP with that in a language that's functional. Blame the library man, because yeah that's messed up. I think this a case of damned if you do, damned if you don't. If they didn't fake OOP people would be pissed. If they do, people will be pissed. Can't please them all. Whatever the case, there are better libs out there.
I totally get where you're coming from if you're more of a backend guy than a frontend one. The web has been a kiddie playground for years that's just starting to grow up. Believe me, that's also part of the reason I posted this. I get it. I feel ya. That's part of the reason I'm a purist / minimalist. But, JavaScript is a nifty language when it's not bastardized.
On a side note, you'll never get away from having IDs be strings with the DOM, but the whole $($($($($('#omg'))))) thing can be avoided.
Jeremy Falcon
|
|
|
|
|
Personally, I find having two acceptable string delimiters useful. If you're building a string that needs to contain double-quotes, you can use single-quotes to delimit it, and vice versa - avoiding having to use an escape sequence in many cases, and improving readability.
My gripes with JavaScript are many - but this isn't one of them. Douglas Crockford enumerated them well: Bad Parts: Appendix B - JavaScript: The Good Parts - O'Reilly Media[^]
Some of these are remedied in ES6, as detailed here (5 JavaScript “Bad” Parts That Are Fixed In ES6 – freeCodeCamp[^]), but not all mainstream browsers support all of these yet.
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
Alan Kay.
|
|
|
|
|
I totally agree with you there man.
Jeremy Falcon
|
|
|
|
|
Jeremy Falcon wrote: Clearly, you're looking at code written by a 5 year old that doesn't know anything about CSS selectors or jQuery.
You're off by 50 years. And this is exactly why Javascript is so hard to learn. There are no (and no good) resources for how to do things other than SO, CP, and dubious forums by 3rd party vendors. Why? Because who the heck is going to write a book on how to do X when, given the multi-dimensional landscape of web development, describing where X is in this trans-dimensional space is pretty much impossible.
Granted, all my examples are related to using jQuery and 3rd party frameworks, but it's impossible to disentangle Javascript from those things when doing web development.
Jeremy Falcon wrote: but the whole $($($($($('#omg'))))) thing can be avoided.
Beats me how to do it. The content of the tree (a jqxwidget) is programatically generated and I haven't figured out a simpler way of getting the text (not to mention the freaking ID) of the parent for a selected node. One option is to represent the tree as a Javascript structure, this would be simple enough to map ID's in the structure to the DOM that jqwidgets creates. And heaven help me if I have to learn one of the Angular/React/etc/ frameworks that jqwidgets claims to support. More obfuscation on top of nebulous indirection.
Yup -- I'm an old fart.
|
|
|
|
|
Marc Clifton wrote: You're off by 50 years. And this is exactly why Javascript is so hard to learn. There are no (and no good) resources for how to do things other than SO, CP, and dubious forums by 3rd party vendors. Why? Because who the heck is going to write a book on how to do X when, given the multi-dimensional landscape of web development, describing where X is in this trans-dimensional space is pretty much impossible. You're absolutely right about that. One of the pain points I have with React learning is simply finding good resources on it. And to top it off, once you find one, it's out-of-date. And to top it off even more, it's not exactly places teach you production ready stuff. It's a royal PITA. The web really is a hodgepodge of kiddie playground crap where nobody wants to agree on anything. About the only reason I was able to even start making any sense of all this crap was a couple years back I pestered a coworker of mine for literally like a year asking him tons of questions.
Marc Clifton wrote: Granted, all my examples are related to using jQuery and 3rd party frameworks, but it's impossible to disentangle Javascript from those things when doing web development. Yeah totally. It is getting better at least, but the web is slow to migrate to new stuff. Being so popular and all there's a lot of existing crap to change before we make way for the new crap. And of course, by that time the new crap will be out-dated.
Marc Clifton wrote: The content of the tree (a jqxwidget) is programatically generated and I haven't figured out a simpler way of getting the text (not to mention the freaking ID) of the parent for a selected node. Having never used that lib, you'd think they'd expose that somehow. Go figure.
Marc Clifton wrote: And heaven help me if I have to learn one of the Angular/React/etc/ frameworks that jqwidgets claims to support. More obfuscation on top of nebulous indirection. But... but... React!
Marc Clifton wrote: Yup -- I'm an old fart. At least you can laugh about it. You reach an age where it's ok to laugh at stuff. That's called maturity. And I'd say I'm 39 so I understand, but I'm sure you'd call me a youngin'.
Jeremy Falcon
|
|
|
|
|
Jeremy Falcon wrote: You reach an age where it's ok to laugh at stuff.
Yeah, works well with one's partner too.
At the end of the day, I end up treating these technologies like everything else, even C#/.NET:
1) Figure out how to do stuff the hard way
2) Look at how to make it easier and learn from others
3) Create a toolbox that mitigates some of the pain points
4) Liberally sprinkle code with // TODO: Kludge! and // TODO: There has to be a better way!
|
|
|
|
|
Marc Clifton wrote: Liberally sprinkle code with // TODO: Kludge! and // TODO: There has to be a better way! I do the same thing too.
Jeremy Falcon
|
|
|
|
|
Just to give you an idea of where the web is headed, here is some ES2015 code...
import React from 'react';
import {Link} from 'react-router';
class Layout extends React.Component {
static propTypes = {
children: PropTypes.object.isRequired
};
render() {
return (
<div className="container-fluid">
<p>header here and all</p>
{this.props.children}
</div>
);
}
};
export default Layout; Btw, that's not HTML inside the render method. It's just syntactic sugar to look like it. It gets transpiled down to JavaScript. But the only strings you'll see here are in the imports (which isn't much different than C/C++ includes) and the properties that will be spit out to the browser such as "container-fluid". Well, there is the literal there too, but none of the $($($($('omg')))) stuff.
Now, I'm not saying everything is perfect with the web. But new-skool web development (especially as WASM gets more popular) is nothing like old-skool web development.
Jeremy Falcon
|
|
|
|
|
(and now I feel guilty about not finishing up the React colourising definitions...)
cheers
Chris Maunder
|
|
|
|
|
Muwahahahahahah. Then my work here is done.
Jeremy Falcon
|
|
|
|
|
Jeremy Falcon wrote: ust to give you an idea of where the web is headed,
Could you provide a translation? That is all but unintelligible.
I have two reactions. I'm sure I can learn this, and maybe even like it. On the other hand, I really don't want to.
|
|
|
|
|