• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Javascript Is freaking CRAZY

Cogman

Lifer
Some of the stuff that you can do with it are insane. For example, giving a class/element an attribute on the fly. Thats just insane. Or using a function pointer on a function with varying numbers of parameters. Its so loose in standards, no wonder people get driven nuts when they try to do something in C++ only to find "You can't do that."

Just saying. I got this revelation after hacking out this piece of code.

Code:
function ajaxUpdate(data)
{
	this.nextSel.empty();
	$(data).find('option').each(function ()
	{
		var ele = $(this);
		var name = ele.attr('name');
		var id = ele.attr('id');
		var Opt = $('<option></option>');
		Opt.text(id + ' - ' + name);
		Opt.attr('value', id);
		$('#exch').append(Opt);
	});
}

$(document).ready(function (){
			setupBrowser();
			setupLayout();
			setupAjax();
			$('#comp').each(function() {
				this.reqVal = 'ce';
				this.nextSel = $('#exch');
				});
			$('#comp').change(function ()
			{
				$.ajax({
					data: { 
						id: $(this).attr('value'),
						// To do: replace with real cookie
						sessionid: 'iifyqq1cg3kn', 
						request: this.reqVal
						},
					success: $.proxy(ajaxUpdate, this),
					error: function()
					{
					}
				});
			});
		});

Feel free to share your "This language is nuts." stories here as well.


(Also, Ignore the indenting... It is somewhat a "work in progress")
 
Crazy flexible, yes, but that doesn't exactly make for easy maintainability. And closures are real easy to screw yourself over in scope. For example:

Code:
var X=2;
someelement.addHandler('click', function(){alert X;}, false);
X = 3;
someotherelement.addHandler('click', function(){alert X;}, false);

will have both elements popping up 3. but...

Code:
var X=2;
ElementHandler(someelement, X);
X = 3;
ElementHandler(someotherelement, X);

function ElementHandler(element, index)
{
element.addHandler('click', function(){alert index;}, false);
}

will have them pop up 2 and 3 respectively. Dangerous when setting closures from a loop.


That's not just javascript you've got there though. It's absolutely hooked up to a framework, probably jQuery.
 
PHP, Perl and Flash ActionScript can be "fun" like that too.

I prefer weird C/C++ pointer madness over loosely typed dynamic interpreted languages any day. Not always having access to single-step debugging to see why it's going horribly wrong is just the icing on the cake.
 
PHP, Perl and Flash ActionScript can be "fun" like that too.

I prefer weird C/C++ pointer madness over loosely typed dynamic interpreted languages any day. Not always having access to single-step debugging to see why it's going horribly wrong is just the icing on the cake.

Oh no, the icing on the cake is "This works on IE 7, but not IE 6"

Dealing with old IE and all its quirks is terrible. I wish IE6 and lower would just die. Unfortunately, the project I'm working on will be for people that are using Win2000 and IE6... 🙁
 
I worked with JS for a while, and there were moments I hated its guts. I'm sure it's fun if you're playing with it on your own, but I was working on a large piece of code that I didn't write and had deadlines, not to mention that this was the first time I worked with JS, and FFS it took me ages to understand what's going on sometimes and why is some code needed at all. C/C++/C# seem so much more organized and understandable.
Also, keyword 'this' seems to be very important in JS, it's fu**ing everywhere... 🙂
 
PhatoseAlpha it's not too mysterious if you think about what's going on. In the first example you closed over a binding and then modified it. In the second example, you forced evaluation (call-by-value) by invoking that function, so you got whatever the value of the variable X was at the point of the call.

And shit, I'm really drunk and I can pick that out.
 
I thought it was interesting when I found out modifying the prototype of an object affects all instances of that object.

Also creating objects and having them extend other objects can be fun in javascript 🙂

It can be frustrating, but once you understand the quirks and what certain error messages mean in different browsers it can be a quite enjoyable language. Also jQuery has made my life a lot easier, prototype I'm not a fan of however.

It is pretty amazing how powerful it is considering it was created by Netscape, however it has undergone a lot of changes since then.

There are also libraries that allow you to write java and it gets converted into javascript. This lets you share objects between the languages from what I hear.
 
Last edited:
Matlab is basically Javascript, isn't it? It's fun to build variable names and create them on the fly, like:

for i=1:10
runString = sprintf('varName&#37;d = %d*42;',i,i);
eval(runString);
end

Totally crazy coming from a very static assembly and C world...

Also, Sgraffite - there are contests here for people who have been around the longest with the fewest posts. I'm pretty sure you'd win. 🙂
 
Adding variables on the fly is a common scripting language attribute. Adding class members, maybe not so much.

No, Matlab is different crazy. It's a language that's only fast when you use SIMD. Instead of looping to multiply two arrays together, you can just say A.*B.

Of course normal loops work too. But since it's so slow the other way, you really have to think SIMD when solving problems.
 
Adding variables on the fly is a common scripting language attribute. Adding class members, maybe not so much.

No, Matlab is different crazy. It's a language that's only fast when you use SIMD. Instead of looping to multiply two arrays together, you can just say A.*B.

Of course normal loops work too. But since it's so slow the other way, you really have to think SIMD when solving problems.

Adding datamembers on the fly is what gets me the most. Its like "Humm, I need an attribute on this object to tell if it has been used or not.. How about I just use it!"

Well, that and being able to call functions with a different call signatures then said function.
 
Adding members at run time is a common feature across most dynamic languages. I don't see the appeal personally, it seems likely to cause more debugging nightmares than anything. Not that I'm a dynamic expert, but give me nice statically type, late-bound languages like C# and Java or powerful and expressive functional languages like F# (still strongly typed) any day. Dynamic typing makes me want to harm myself.
 
Back
Top