Skip to content
This repository has been archived by the owner on Oct 26, 2021. It is now read-only.

Commit

Permalink
Farewell CoffeeScript
Browse files Browse the repository at this point in the history
We are breaking up. I'm sorry, it's not you, it's me. I really like
you, but I feel like now is that time in my life where I grow up
and face some big challenges and decisions.
The first time I saw you, I couldn't take my eyes off of your
beautiful list comprehensions. Your arrow functions were amazing.
I bet you remember all the special moments we had together. It was
pretty fantastic. It was love at first sight.

You remind me of my parents, Mr. Python and Mrs. Ruby, who taught
me great things in life. But now, I can make my own decisions
independently of my parents. As I said, there's nothing really wrong
with you. It's just that I need to go dangerous, I need to live that
adventure that every man is called to. To take my backpack and just
go, discover the world out there.

With you, I don't have my freedom to name my own functions. I can't
make classes the way I want to. You don't let me do that. And I know
your intentions are the best, please don't get offended here. I know
you are trying to save me against evil code and odd bugs. But I have
grown up and those aren't issues anymore. Also, in the end of the
day, your generated JavaScript is just about 5% more verbose than
actual CoffeeScript code, so I don't see real benefit.

I think I'll survive. This time, I actually believe I can JavaScript.
I don't particularly like it, I miss you sometimes, my dear.
But I got courage. This will be tough, but it's my destiny. It's what
I'm called to do. Sorry.
  • Loading branch information
Andre Medeiros committed Oct 2, 2014
1 parent cf985c9 commit 57e37f1
Show file tree
Hide file tree
Showing 49 changed files with 2,330 additions and 3,992 deletions.
1 change: 1 addition & 0 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ DONE Render nondraggable Completion for output diagram
DONE Controller logic to include completion time
DONE Update examples with regard to completion time
DONE New Model View Interpreter architecture, for OperatorsMenu
TODO Replace CoffeeScript with JavaScript

This comment has been minimized.

Copy link
@totty90

totty90 Oct 2, 2014

Best decision (:

This comment has been minimized.

Copy link
@cympfh

cympfh Oct 3, 2014

Nice

TODO Lower bound on completion time, no earlier than any marble time
- Marble has a static subject for mousedown event, which covers all instances
of marble. Each subject notification points to the marble instance's id. ALSO
Expand Down
3,895 changes: 1,021 additions & 2,874 deletions dist/js/app.js

Large diffs are not rendered by default.

40 changes: 21 additions & 19 deletions dist/js/binder.js

Large diffs are not rendered by default.

20 changes: 6 additions & 14 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var gulp = require('gulp');
var coffee = require('gulp-coffee');
var less = require('gulp-less');
var browserify = require('gulp-browserify');
var uglify = require('gulp-uglify');
Expand All @@ -9,13 +8,6 @@ var path = require('path');

// Based on https://github.com/deepak1556/gulp-browserify/issues/7

gulp.task('coffee', function() {
gutil.log(gutil.colors.yellow("Compiling CoffeeScript..."));
return gulp.src(['./src/**/*.coffee'])
.pipe(coffee({bare: true}).on('error', gutil.log))
.pipe(gulp.dest('./build/src'));
});

gulp.task('less', function() {
gutil.log(gutil.colors.yellow("Compiling LESS styles..."));
gulp.src('./styles/main.less')
Expand All @@ -25,19 +17,19 @@ gulp.task('less', function() {
.pipe(gulp.dest('./dist/css'));
});

gulp.task('dev-browserify', ['coffee'], function() {
gulp.task('dev-browserify', [], function() {
gutil.log(gutil.colors.yellow("Packing with browserify..."));
return gulp.src(['./build/src/**/*.js'])
return gulp.src(['./src/**/*.js'])
.pipe(browserify({
insertGlobals: true,
debug: true
}))
.pipe(gulp.dest('./build/browserified-js'));
});

gulp.task('browserify', ['coffee'], function() {
gulp.task('browserify', [], function() {
gutil.log(gutil.colors.yellow("Packing with browserify..."));
return gulp.src(['./build/src/**/*.js'])
return gulp.src(['./src/**/*.js'])
.pipe(browserify({
insertGlobals: false,
debug: false,
Expand All @@ -57,7 +49,7 @@ gulp.task('uglify', ['browserify'], function() {
gulp.task('post-clean-up', ['uglify'], function() {
gutil.log(gutil.colors.yellow("Cleaning up temporary files..."));
return gulp.src(
[__dirname+'/build/src/**/*', __dirname+'/build/browserified-js/**/*'],
[__dirname+'/build/browserified-js/**/*'],
{read: false}
)
.pipe(rimraf());
Expand All @@ -74,7 +66,7 @@ gulp.task('default', function() {
gulp.run('dev-build');

gutil.log("Watching for changes...");
gulp.watch(['./src/**/*.coffee', './styles/**/*.less'], function(event) {
gulp.watch(['./src/**/*.js', './styles/**/*.less'], function(event) {
if (event.path) {
gutil.log("Change detected in ", gutil.colors.magenta(event.path));
} else {
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@
},
"devDependencies": {
"browserify": "~2.36.0",
"coffeeify": "~0.6.0",
"gulp": "~3.8.6",
"gulp-browserify": "^0.5.0",
"gulp-coffee": "^2.1.1",
"gulp-less": "^1.3.2",
"gulp-rimraf": "^0.1.0",
"gulp-uglify": "^0.3.1",
Expand All @@ -30,7 +28,7 @@
},
"scripts": {
"preinstall": "rm -rf build && rm -rf node_modules",
"postinstall": "mkdir build && mkdir build/src && ln -s ../build/src node_modules/rxmarbles && ln -s ../package.json node_modules/package.json",
"postinstall": "ln -s ../src node_modules/rxmarbles && ln -s ../package.json node_modules/package.json",
"update-gh-pages": "git checkout gh-pages && git merge master && rm dist/js/app.js && gulp build && git add dist/js/app.js && git commit --amend --no-edit && git push origin gh-pages && git checkout master"
}
}
31 changes: 0 additions & 31 deletions src/app.coffee

This file was deleted.

31 changes: 31 additions & 0 deletions src/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* App entry-point.
*/
var Package = require('package.json');
var binder = require('rxmarbles/binder');
var Sandbox = require('rxmarbles/views/sandbox');
var OperatorsMenuModel = require('rxmarbles/models/operators-menu');
var OperatorsMenuView = require('rxmarbles/views/operators-menu');
var OperatorsMenuInterpreter = require('rxmarbles/interpreters/operators-menu');
var DOMDelegator = require('dom-delegator');
var Utils = require('rxmarbles/views/utils');

var domDelegator = DOMDelegator();

var sandboxContainer = document.querySelector(".js-sandboxContainer");
sandboxContainer.innerHTML = "";
sandboxContainer.appendChild(Sandbox.render());

binder(OperatorsMenuModel, OperatorsMenuView, OperatorsMenuInterpreter);
// binder(SandboxModel, SandboxView, SandboxInterpreter);

Utils.renderVTreeStream(OperatorsMenuView.vtree$, ".js-operatorsMenuContainer");

var versionElement = document.querySelector("a.js-appVersion");
versionElement.textContent = "v" + Package.version;
versionElement.href = "https://github.com/staltz/rxmarbles/releases/tag/v" + Package.version;

var rxVersion = Package.dependencies.rx.replace(/(~|\^|\.\+)*/g, "");
var rxElement = document.querySelector("a.js-rxjsVersion");
rxElement.textContent = "RxJS v" + rxVersion;
rxElement.href = "https://github.com/Reactive-Extensions/RxJS/tree/v" + rxVersion;
8 changes: 0 additions & 8 deletions src/binder.coffee

This file was deleted.

8 changes: 8 additions & 0 deletions src/binder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* Important Model-View-Interpreter binding function.
*/
module.exports = function(model, view, interpreter) {
view.observe(model);
interpreter.observe(view);
model.observe(interpreter);
};
38 changes: 0 additions & 38 deletions src/data/boolean-examples.coffee

This file was deleted.

48 changes: 48 additions & 0 deletions src/data/boolean-examples.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
var Rx = require('rx');

module.exports = {
"all": {
"label": "all(x => x < 10)",
"inputs": [
[{t:5, d:1}, {t:15, d:2}, {t:25, d:3}, {t:35, d:4}, {t:65, d:5}, 80]
],
"apply": function(inputs) {
return inputs[0].all(function(x) { return x.content < 10; });
}
},

"any": {
"label": "any(x => x > 10)",
"inputs": [
[{t:5, d:2}, {t:15, d:30}, {t:25, d:22}, {t:35, d:5}, {t:45, d:60}, {t:55, d:1}]
],
"apply": function(inputs) {
return inputs[0].any(function(x) { return x.content > 10; });
}
},

"contains": {
"label": "contains(22)",
"inputs": [
[{t:5, d:2}, {t:15, d:30}, {t:25, d:22}, {t:35, d:5}, {t:45, d:60}, {t:55, d:1}]
],
"apply": function(inputs) {
return inputs[0].contains({ content: 22 }, function(x, y) {
return x.content === y.content;
});
}
},

"sequenceEqual": {
"label": "sequenceEqual",
"inputs": [
[{t:5, d:1}, {t:15, d:2}, {t:25, d:3}, {t:35, d:4}, {t:65, d:5}, 85],
[{t:2, d:1}, {t:20, d:2}, {t:40, d:3}, {t:70, d:4}, {t:77, d:5}, 85]
],
"apply": function(inputs) {
return inputs[0].sequenceEqual(inputs[1], function(x, y) {
return x.content === y.content;
});
}
}
};
58 changes: 0 additions & 58 deletions src/data/combine-examples.coffee

This file was deleted.

72 changes: 72 additions & 0 deletions src/data/combine-examples.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
var Rx = require('rx');

module.exports = {
"combineLatest": {
"label": "combineLatest((x, y) => \"\" + x + y)",
"inputs": [
[{t:0, d:1}, {t:20, d:2}, {t:65, d:3}, {t:75, d:4}, {t:92, d:5}],
[{t:10, d:"A"}, {t:25, d:"B"}, {t:50, d:"C"}, {t:57, d:"D"}]
],
"apply": function(inputs) {
return Rx.Observable.combineLatest(inputs[0], inputs[1], function(x, y) {
return "" + x.content + y.content;
});
}
},

"concat": {
"label": "concat",
"inputs": [
[{t:0, d:1}, {t:15, d:1}, {t:50, d:1}, 57],
[{t:0, d:2}, {t:8, d:2}, 12]
],
"apply": function(inputs) {
return Rx.Observable.concat(inputs);
}
},

"merge": {
"label": "merge",
"inputs": [
[{t:0, d:20}, {t:15, d:40}, {t:30, d:60}, {t:45, d:80}, {t:60, d:100}],
[{t:37, d:1}, {t:68, d:1}]
],
"apply": function(inputs) {
return Rx.Observable.merge(inputs);
}
},

"sample": {
"label": "sample",
"inputs": [
[{t:0, d:1}, {t:20, d:2}, {t:40, d:3}, {t:60, d:4}, {t:80, d:5}],
[{t:10, d:"A"}, {t:25, d:"B"}, {t:33, d:"C"}, {t:70, d:"D"}, 90]
],
"apply": function(inputs) {
return inputs[0].sample(inputs[1]);
}
},

"startWith": {
"label": "startWith(1)",
"inputs": [
[{t:30, d:2}, {t:40, d:3}]
],
"apply": function(inputs, scheduler) {
return inputs[0].startWith(scheduler, 1);
}
},

"zip": {
"label": "zip",
"inputs": [
[{t:0, d:1}, {t:20, d:2}, {t:65, d:3}, {t:75, d:4}, {t:92, d:5}],
[{t:10, d:"A"}, {t:25, d:"B"}, {t:50, d:"C"}, {t:57, d:"D"}]
],
"apply": function(inputs) {
return Rx.Observable.zip(inputs[0], inputs[1], function(x, y) {
return "" + x.content + y.content;
});
}
}
};
Loading

27 comments on commit 57e37f1

@zaidakram
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Loved it! 👏

@buro9
Copy link

@buro9 buro9 commented on 57e37f1 Oct 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Congrats, though https://github.com/staltz/rxmarbles/blob/master/README.md still says that the project is CoffeeScript. A very minor oversight given the size of this commit.

@staltz
Copy link
Owner

@staltz staltz commented on 57e37f1 Oct 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, good point. Thanks. @buro9

@mvasilkov
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good decision indeed, cheers.

@totty90
Copy link

@totty90 totty90 commented on 57e37f1 Oct 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Best decision (:

@mdesantis
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello!

With you, I don't have my freedom to name my own functions. I can't
make classes the way I want to. You don't let me do that.

Could you please explain this? I'm interested in it 👂

@staltz
Copy link
Owner

@staltz staltz commented on 57e37f1 Oct 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mdesantis

Could you please explain this? I'm interested in it

foo = (x) -> 2*x
console.log foo(5)

Gets compiled to

// Generated by CoffeeScript 1.7.1
(function() {
  var foo;

  foo = function(x) {    // I want `foo = function foo(x) {`
    return 2 * x;
  };

  console.log(foo(5));

}).call(this);

For debugging purposes, etc.

@bstst
Copy link

@bstst bstst commented on 57e37f1 Oct 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can have your foo: http://coffeescript.org/#lexical-scope
Properly written CoffeeScript has everything you mentioned there in your complaints.

And it's sad -- you're drawing your own conclusions without even learning the topic in interest. CoffeeScript will never be an advantage when not used properly.

@staltz
Copy link
Owner

@staltz staltz commented on 57e37f1 Oct 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can have your foo: http://coffeescript.org/#lexical-scope

Exactly where? I didn't find it even with the browser's search.

@bstst
Copy link

@bstst bstst commented on 57e37f1 Oct 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

➜  Desktop  node_modules/.bin/coffee -p test.coffee   
(function() {
  var foo;

  foo = function(x) {
    return 2 * x;
  };

}).call(this);
➜  Desktop  node_modules/.bin/coffee -b -p test.coffee
var foo;

foo = function(x) {
  return 2 * x;
};
➜  Desktop  

Notice the -b switch -- it would solve this particular issue.

@staltz
Copy link
Owner

@staltz staltz commented on 57e37f1 Oct 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is completely not what I'm talking about. Notice the comment here in the middle of the code:

// Generated by CoffeeScript 1.7.1
(function() {
  var foo;

  foo = function(x) {    // I want `foo = function foo(x) {`
    return 2 * x;
  };

  console.log(foo(5));

}).call(this);

@staltz
Copy link
Owner

@staltz staltz commented on 57e37f1 Oct 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bstst
Copy link

@bstst bstst commented on 57e37f1 Oct 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed pardon me. But, Note that there is a solution to the scoping issue, and it is employed for class constructors, primarily for reflection purposes, but the resulting code is too verbose to use for every function.. The answer is use classes. How it technically is supposed to be in OOP. But since you're using Rx, the compiled code would most probably be an overkill. Thus, a proper solution -- sourcemaps.

@mvasilkov
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bstst no, the proper solution is dropping the toy language.

@staltz
Copy link
Owner

@staltz staltz commented on 57e37f1 Oct 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I wouldn't use classes. That would be a hackaround for such an obvious feature that needs to be there.

@davelnewton
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[...] your generated JavaScript is just about 5% more verbose than
actual CoffeeScript code, so I don't see real benefit [...]

Other pros/cons aside, the point of CS isn't to minimize the generated JS, and I'm almost positive you know that--I don't understand why you brought that up.

@bstst
Copy link

@bstst bstst commented on 57e37f1 Oct 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A hackaround is the var foo = function foo notation. It's just wrong. Don't blame CS or MS for this. Blame JS itself.

@mvasilkov, unless you're doing functional programming, CS is quite awesome. I've been on your side of the opinion for quite a long time. CS is not intended to fix all JS issues. It's just a perfect OOP JS wrapper.

@staltz
Copy link
Owner

@staltz staltz commented on 57e37f1 Oct 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the point of CS isn't to minimize the generated JS, and I'm almost positive you know that

Well, in my mind one of the points of CS is really to make JS less verbose. I wouldn't say "minimize", but less verbosity. It's a point for me, yes. I appreciated it to some extent (and lots of other people appreciate it too, under the argument of readability).

@staltz
Copy link
Owner

@staltz staltz commented on 57e37f1 Oct 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A hackaround is the var foo = function foo notation. It's just wrong. Don't blame CS or MS for this. Blame JS itself.

I'm 100% convinced that JavaScript sucks. I said, I like CoffeeScript, but JavaScript exists, and we can't deny that. It exists and some things you just have to do it the JavaScript way. You can't have any other language on the browser.

@davelnewton
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one of the points of CS is really to make JS less verbose

@staltz Right, it makes JS less verbose by not being JS. The point is to write your code in CS, which is less verbose than JS, and not worry about the generated JS. (The reality is that you occasionally need to look at the generated JS, but that's a separate issue.) 5% is essentially nothing, and gets minimized anyway.

An argument against CS because it generates marginally more JS than hand-written JS, to me, doesn't make sense: when using CS, CS is the artifact you deal with (delta the occasional caveat mentioned above).

I'm ambivalent on the CS v. JS thing myself, but I can't get behind this particular reason, I guess.

@staltz
Copy link
Owner

@staltz staltz commented on 57e37f1 Oct 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davelnewton I like to compare this with C vs Assembly. C is in many ways Assembly in disguise, but if you take a C artifact, it is probably 40%~60% (statistics from my mind) the size of the corresponding hand-written Assembly or generated Assembly.

In Javascript vs CoffeeScript, the CS artifact is just about 95% the size of the corresponding JS artifact. And you can see that clearly on this commit. Check for instance these two files operators-menu.* 57e37f1#diff-be22ef9a6ad6adba18c1392e56f085d8L1 .

@bstst
Copy link

@bstst bstst commented on 57e37f1 Oct 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's because of all the unnecessary parentheses, commas and braces in your CS! ;)

@staltz
Copy link
Owner

@staltz staltz commented on 57e37f1 Oct 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comma/parentheses strip tease is the most useless feature (and often confusing) that I've found in CS, and I'm no way obliged to use it, so I've never used it.

PS: also, that would only affect the length of lines, not the number of lines. ;)

@davelnewton
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@staltz Agreed, in this short, simple example, there isn't much benefit, although I personally find less braces etc. easier on the eyes--but that is almost completely non-technical and opinionated. I would have written that CS slightly differently, but largely agree.

I don't think the benefits of CS are readily apparent in small, isolated examples, though.

Like I said, overall I'm ambivalent :)

@staltz
Copy link
Owner

@staltz staltz commented on 57e37f1 Oct 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I said, I still like CoffeeScript! I just couldn't let it get in my way this time.

@MFQ
Copy link

@MFQ MFQ commented on 57e37f1 Oct 3, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good decision, one day Javascript will rule !!!!

@ColCh
Copy link

@ColCh ColCh commented on 57e37f1 Oct 4, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's right move!

Please sign in to comment.