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
Posting Principle
Dec 10, 2011

by Ralp
javascript is for dom manipulation, not servers

Adbot
ADBOT LOVES YOU

Count Thrashula
Jun 1, 2003

Death is nothing compared to vindication.
Buglord

"the future of programming" & "node.js"

two things that should never be in the same sentence.

but if you ARE doing jscript stuff, coffeescript is pretty neat. i mean it's literally just shorthand that a second program takes and goes *beep boop boop beep* and turns your shorthand into regular pain-in-the-rear end javascript

i mean really, which is easier

code:
function butts(thing){
  //stuff
}
or

code:
butts (thing) ->
  //stuff

abraham linksys
Sep 6, 2010

:darksouls:

i barely GNU her! posted:

so exactly what is the point of coffeescript again


is it ~my artisinal handcrafted whitespace~

yea it's got some syntatic similarities to ruby

there's a handful of functional differences, too (list comprehensions, splats, classes) but not anything significant. some people find it more enjoyable to write, and i don't have trouble debugging what comes out of it, so i don't have any issues with it

Posting Principle posted:

javascript is for dom manipulation, not servers

:) actually javascript runs on a variety of platforms and is used for various tasks, including servers, build tools, and command-line scripts!

e: lawdy people on this website get mad about programming languages

Count Thrashula
Jun 1, 2003

Death is nothing compared to vindication.
Buglord
semantic white text is the future of programming

Quebec Bagnet
Apr 28, 2009

mess with the honk
you get the bonk
Lipstick Apathy
are braces really a pain in the rear end to write though

abraham linksys
Sep 6, 2010

:darksouls:

QPZIL posted:

"the future of programming" & "node.js"

two things that should never be in the same sentence.

i agree with this as long as you don't think the future of programming includes python, perl, ruby, java, c, or basically anything that exists outside of bret victor's mind

also haskell feels a bit space-agey, so that's acceptable. and david nolen still blows my mind whenever he posts a clojure(script) snippet, so that's probably included somewhere in the future too

btw one random note: anyone who starts talking about languages as being "academic" or "practical" are dumb. i mean poo poo jane street makes a billion dollars using loving ocaml; someone could build a business off haskell if they really wanted to

jooky
Jan 15, 2003

can I ask you about your bespoke JavaScript web framework of the week

abraham linksys
Sep 6, 2010

:darksouls:

jooky posted:

can I ask you about your bespoke JavaScript web framework of the week

i actually started on a fakepost about facebook's react framework but i don't think i could pretend to like the concept of inline psuedo-XML in javascript

(really the only two frameworks i ever use are ember and angular and they've both been around for years and people are building startups just fine off of them so w/e)

MononcQc
May 29, 2007

oh god are we talking about node.js' concurrency model right now? things I get caremad about.

Tiny Bug Child
Sep 11, 2004

Avoid Symmetry, Allow Complexity, Introduce Terror

QPZIL posted:

i mean really, which is easier

code:
function butts(thing){
  //stuff
}
or

code:
butts (thing) ->
  //stuff

is this a trick question? it's the first one. there are no braces in the second one. there's no keyword that tells you what it is. it's unreadable. i mean i guess it's a function definition, since i assume that's the coffeescript equivalent, but there are no braces. how do you know when the function is over?

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
i missed you tbc

Count Thrashula
Jun 1, 2003

Death is nothing compared to vindication.
Buglord

Tiny Bug Child posted:

there are no braces. how do you know when the function is over?

QPZIL posted:

semantic white text is the future of programming

Tiny Bug Child
Sep 11, 2004

Avoid Symmetry, Allow Complexity, Introduce Terror
it's good that coffeescript can be directly interpreted into js. that way when your boss finds out you wrote something in a fake language they'll be able to turn it into some really ugly javascript after you get fired

Shaggar
Apr 26, 2006

QPZIL posted:

"the future of programming" & "node.js"

two things that should never be in the same sentence.

but if you ARE doing jscript stuff, coffeescript is pretty neat. i mean it's literally just shorthand that a second program takes and goes *beep boop boop beep* and turns your shorthand into regular pain-in-the-rear end javascript

i mean really, which is easier

code:
function butts(thing){
  //stuff
}
or

code:
butts (thing) ->
  //stuff

the first one is better except for the incorrect opening bracket placement

Tiny Bug Child
Sep 11, 2004

Avoid Symmetry, Allow Complexity, Introduce Terror

QPZIL posted:

semantic white text is the future of programming

i still can't believe there are people who can take languages with semantic whitespace seriously

Tiny Bug Child
Sep 11, 2004

Avoid Symmetry, Allow Complexity, Introduce Terror

Shaggar posted:

the first one is better except for the incorrect opening bracket placement

yes. it needs a space between the () and the {

Shaggar
Apr 26, 2006

Tiny Bug Child posted:

i still can't believe there are people who can take languages with semantic whitespace seriously

no one takes them seriously.

abraham linksys
Sep 6, 2010

:darksouls:

MononcQc posted:

oh god are we talking about node.js' concurrency model right now? things I get caremad about.

ooh if you have an opinion on this i'd like to hear it because you're one of the few programmers who, unlike me, knows what the gently caress they're talking about

in particular i'm curious if there's any deficiencies in node's callback-based concurrency that can't be massaged over with generators or promises

abraham linksys
Sep 6, 2010

:darksouls:

Tiny Bug Child posted:

yes. it needs a space between the () and the {

Tiny Bug Child posted:

is this a trick question? it's the first one. there are no braces in the second one. there's no keyword that tells you what it is. it's unreadable. i mean i guess it's a function definition, since i assume that's the coffeescript equivalent, but there are no braces. how do you know when the function is over?

Shaggar posted:

the first one is better except for the incorrect opening bracket placement

anyone who holds strong opinions about these things must have an incredibly boring loving job

if you don't encounter anything more interesting in your programming career i feel bad for you :smith:

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip
the only way to fix node's deficiencies is with italian bread.



















































































































to mop up the callback soup

abraham linksys
Sep 6, 2010

:darksouls:

Otto Skorzeny posted:

the only way to fix node's deficiencies is with italian bread.
`['\n' for x in range(1,100)]`
to mop up the callback soup

brb creating github.com/italian-bread.js.git

because the world doesnt have enough promises libraries

Zaxxon
Feb 14, 2004

Wir Tanzen Mekanik

MononcQc posted:

oh god are we talking about node.js' concurrency model right now? things I get caremad about.

node.js has a concurrency model? I thought it was strictly a single threaded event loop, and if you wanted concurrency you had to do multiple processes.

Zombywuf
Mar 29, 2008

abraham linksys posted:

also people are still angry about coffeescript

coffeescript

coffeescript should be the least offensive language on earth. i mean it's fine if you want to freak out about it in yospos because it's pretty goofy, but in practice using it is meaningless and will have no effect on your ability to do things. i mean, the only valid argument is that yeah coffeescript will probably lose more users as es6 matures, but its compiled output is completely human readable and writable, so who cares

When this list reaches 0 entries coffeescript will stop being a joke: https://github.com/satyr/coco/wiki/wtfcs

I pity the people who have to use it, check out some old versions of that page.

MrMoo
Sep 14, 2000

I read on Chrome Status we're getting something like this:

code:
butts (thing) => {
  // stuff
}
It's already in Firefox.

abraham linksys
Sep 6, 2010

:darksouls:

MrMoo posted:

I read on Chrome Status we're getting something like this:

code:
butts (thing) => {
  // stuff
}
It's already in Firefox.

yea

JavaScript code:
salaryList = employeeList.map(function (e) { return e.salary; });

// is equal to
salaryList = employeeList.map(e => e.salary);

// is equal to
salaryList = employeeList.map(e => { return e.salary });
JavaScript code:
var total = employeeList.map(e => e.salary).reduce(function(p, q) { return p + q });

// is equal to
var total = employeeList.map(e => e.salary).reduce((p, q) => p + q));
(via http://ariya.ofilabs.com/2013/02/es6-and-arrow-function.html)

Opinion Haver
Apr 9, 2007

i always wondered if there's a nice shorthand for lambda x: x.foo or e => e.foo or whatever, or is it just not worth the trouble

crazypenguin
Mar 9, 2005
nothing witty here, move along

yaoi prophet posted:

i always wondered if there's a nice shorthand for lambda x: x.foo or e => e.foo or whatever, or is it just not worth the trouble

I use a little academic language where that's (.foo) and it's pretty nice

can look a little weird though sometimes when you're writing map((.foo), whatever)

leterip
Aug 25, 2004

yaoi prophet posted:

i always wondered if there's a nice shorthand for lambda x: x.foo or e => e.foo or whatever, or is it just not worth the trouble

How terrible is this:

Python code:
select = type("select", (object,), {"__getattr__": lambda _, p: lambda x: getattr(x, p)})()

class Bar(object):
	def __init__(self, x):
		self.x = x

print map(select.x, [Bar(2), Bar(3), Bar(4)])

Lysidas
Jul 26, 2002

John Diefenbaker is a madman who thinks he's John Diefenbaker.
Pillbug
very

did you even try to run it

code:
$ python select.py 
  File "select.py", line 7
    print map(select.x, [Bar(2), Bar(3), Bar(4)])
            ^
SyntaxError: invalid syntax

Max Facetime
Apr 18, 2009

perfect opportunity to introduce

pre:
butts (thing) ⇒ {
  // stuff
}
missed!

MononcQc
May 29, 2007

Zaxxon posted:

node.js has a concurrency model? I thought it was strictly a single threaded event loop, and if you wanted concurrency you had to do multiple processes.

Concurrency and parallelism aren't the same thing. Concurrency is the ability to design and having multiple distinct tasks run and complete over overlapping time periods. For example, when your OS would run multiple programs (say notepad.exe and a browser) on a single core.

Parallelism is running multiple tasks at the same time.

You can have both at the same time, say with Erlang, Go, Rust, Clojure, or Scala, when different actors/threads/processes/routines run on different cores. You can have concurrency without parallelism when a program in one of the languages above runs on a single core, too.

You can have parallelism without concurrency: any execution that your hardware executes in parallel to speed things up without you knowing about it, stuff you send over a GPU, and so on.

Callback-based code is a concurrency model, one of the most primitive ones, where the user manually breaks up computations into individual functions or routines, to be called on some events.

abraham linksys posted:

ooh if you have an opinion on this i'd like to hear it because you're one of the few programmers who, unlike me, knows what the gently caress they're talking about

in particular i'm curious if there's any deficiencies in node's callback-based concurrency that can't be massaged over with generators or promises

Promises help. They're one of the other concurrency tools that are nicer than callbacks. The general problem I have with callback/event loops as a concurrency construct for a server application like node.js is that they're antique pieces of crap compared to nicer techniques available today. I posted a long rant on this before, but here it is again in condensed form.

1. Callback-based code is cooperative, thus risky for a server-side app because any bad dev can make a rarely-called CPU-intensive task block extremely common and simple requests.

2. Coordinating multiple callbacks on to a single point sucks. You need some equivalent to a counter that's used to know how many callbacks are left to run:

code:
fetch_images() {
    var total = 3;
    var ok = new container();
    var bad = new container();
    var callback = function(e) {
        if (e.success()) {
            ok.push(e);
        else {
            bad.push(e);
        }
        total -= 1;
        if (total == 0) {
            next_step(ok, bad);
        }
    }
    some_lib.async_fetch(img1, callback); 
    some_lib.async_fetch(img2, callback);
    some_lib.async_fetch(img3, callback);       
}
This is a load of poo poo. Promises, futures, or channels help make it better:

code:
keys.push(some_lib.future(img1));
keys.push(some_lib.future(img2));
keys.push(some_lib.future(img3));
var ok = new container();
var bad = new container();
for (key in keys) {
    res = some_lib.fetch(key);
    if (res.success()) {
        ok.push(res);
    } else {
        bad.push(res);
    }
}
next_step();
For that kind of promises/futures, the code is already much nicer, can be read in the order you want, doesn't rely on counters, and if you want to prioritize some fetches over others (say one is vital but the rest is not), it's extremely easy to extend the code to do that. It's also easy to make things look blocking without necessarily being scheduled that way. Sadly, a lot of promises or futures libraries in node.js don't have the flexibility to represent things that way without a lot of care and design whereas other languages or frameworks have that in a much more natural manner.

Most models that are somewhat modern will let you wait on another component, do things somewhat asynchronously if you want to, and so on. Lua coroutines and Go goroutines can be examples of that.

3. Callback-based concurrency with event loops is generally far less readable than any other alternative giving similar results: it's hard to follow, debug, trace, etc. The only reason it's acceptable is that it's somewhat trivial to add that model to a code base or language that doesn't support it.

4. Node.js does not support anything really parallel, but even if it had it, callbacks would still be unreadable code compared to other alternatives.

5. I don't like the idea of using the same language in the front-end and the back-end if they're not made specifically for that. You know how to use a knife, so you bring a knife to a modern war fought with guns, tanks, and missiles while shouting "at least I can use the same tools when I eat and when I fight! I save so much time!"

I welcome javascript on the server the way I welcome Java applets in my browser.

6. Event matrix explosion. For example, if you're implementing state machines, you get a bunch of events and a bunch states where they can be used in. This gives you an event-state matrix a bit as follows (for a phone):



The blue items are events and states we care about directly. The red ones are transitional states that each should have 1 input (begin state -> end state). An O means we accept the event. A dash means we queue it up for later (too busy to handle). A D means we deny it. An X means it shouldn't be allowed in the first place.

Using a good language to program a state machine in, you can care only about the blue overlay box, the Ds and the Os. It's trivial to implement ways to block the rest or make it not happen. Either because you can interact with the FSM directly (or blocking, or explicitly controlling the flow of events), or because it has constructs to deal with such messages (selective receiving, dedicated channels, etc.)

Using callback-based code, you do not control what (event, state) combination you will get, and while some are not gonna happen, many of them are possible through annoying combinations. You need to prepare code to handle that explicitly in the least pleasant way possible.

Given how much of a program can be seen as a state machine (whether formal or not), the general state of an event-loop with callback program is a nightmare to handle compared to the rest of stuff.

I'm sure I can think of more, but this is longer than I intended already.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Zombywuf posted:

When this list reaches 0 entries coffeescript will stop being a joke: https://github.com/satyr/coco/wiki/wtfcs

I pity the people who have to use it, check out some old versions of that page.

that whole page is just a list of "don't hold it like that" tier problems

yeah it doesn't nest comprehensions correctly

the fix is don't nest comprehensions you rear end, humans can't understand that either

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

yaoi prophet posted:

i always wondered if there's a nice shorthand for lambda x: x.foo or e => e.foo or whatever, or is it just not worth the trouble

import operator

operator.namegetter("foo")

tef
May 30, 2004

-> some l-system crap ->

abraham linksys posted:

lawdy people on this website get mad about programming languages

hi

tef
May 30, 2004

-> some l-system crap ->

crazypenguin posted:

I use a little academic language where that's (.foo) and it's pretty nice

this is what i've wanted /forever/

i mean in python you can pass around methods as functions so uh, (.foo) (+) etc would be lovely.

i mean seriously

sorted(foo, key=(.butt))

Malcolm XML
Aug 8, 2009

I always knew it would end like this.

tef posted:

this is what i've wanted /forever/

i mean in python you can pass around methods as functions so uh, (.foo) (+) etc would be lovely.

i mean seriously

sorted(foo, key=(.butt))

Control.lens


>:)

tef
May 30, 2004

-> some l-system crap ->

Suspicious Dish posted:

import operator

operator.namegetter("foo")

:some sort of vomiting emoticon:

b0lt
Apr 29, 2005

yaoi prophet posted:

i always wondered if there's a nice shorthand for lambda x: x.foo or e => e.foo or whatever, or is it just not worth the trouble

scala has _.foo

Opinion Haver
Apr 9, 2007

Malcolm XML posted:

Control.lens


>:)

that's exactly what i was thinking of when i made that post

Adbot
ADBOT LOVES YOU

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

tef posted:

:some sort of vomiting emoticon:

python is the purest form of code poetry

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