TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Google Blockly - a visual programming language

258 点作者 antichaos将近 13 年前

45 条评论

ianbishop将近 13 年前
I made a prime sieve: <a href="http://i.imgur.com/Elk5A.png" rel="nofollow">http://i.imgur.com/Elk5A.png</a><p>It was pretty fun.<p>JS generated isn't so bad..<p><pre><code> var n; var A; var i; var x; var j; n = 100; A = []; for (i = 0; i &#60;= n; i++) { A[i - 1] = true; } var i_end = Math.sqrt(n); for (i = 2; i &#60;= i_end; i++) { if (A[i - 1] == true) { j = Math.pow(i, 2); while (j &#60;= n) { A[j - 1] = false; j = (j || 0) + i; } } } for (x = 2; x &#60;= n; x++) { window.alert([x,': ',A[x - 1]].join('')); }</code></pre>
评论 #4051164 未加载
评论 #4051543 未加载
评论 #4050940 未加载
jhuni将近 13 年前
The name of this language immediately made me think of the blocky.io (<a href="http://blocky.io/" rel="nofollow">http://blocky.io/</a>) visual programming language, which was written in Common Lisp by David O'Toole before this language was developed. Blocky.io is <i>very</i> similar to this language, in more then just name, it even has its own MIT scratch like interface: <a href="http://blocky.io/blog/wp-content/uploads/2012/03/Screenshot-1-300x217.png" rel="nofollow">http://blocky.io/blog/wp-content/uploads/2012/03/Screenshot-...</a>.
dxbydt将近 13 年前
i solved a problem featured on the yc company interviewstreet.com codesprint.<p>the problem: Count the number of one-bits from 0 to 2^n - 1, for n from 1 to 20.<p>my solution: <a href="http://i.imgur.com/hUxt0.png" rel="nofollow">http://i.imgur.com/hUxt0.png</a><p>when you run the solution:<p><pre><code> Number of one-bits in 1 bit numbers from 0 to 1 = 1 Number of one-bits in 2 bit numbers from 0 to 3 = 4 Number of one-bits in 3 bit numbers from 0 to 7 = 12 Number of one-bits in 4 bit numbers from 0 to 15 = 32 Number of one-bits in 5 bit numbers from 0 to 31 = 80 Number of one-bits in 6 bit numbers from 0 to 63 = 192 Number of one-bits in 7 bit numbers from 0 to 127 = 448 ....</code></pre> JS:<p><pre><code> var list; var x; var prev; var onebits; var doubleatprev; list = []; list[0] = 1; list[1] = 4; for (x = 2; x &#60;= 20; x++) { prev = x; onebits = Math.pow(2, prev); doubleatprev = list[x - 1] * 2; list[1 + x - 1] = onebits + doubleatprev; } for (x = 1; x &#60;= 20; x++) { window.alert(['Number of one-bits in ',x,' bit numbers from 0 to ',Math.pow(2, x) - 1,' = ',list[x - 1]].join('')); } </code></pre> Took 15 minutes to code up and 45 minutes to debug the array indexing :) One of these days I'll be able to write the JS and get the Blockly instead of the other way around - that'd be super awesome!
评论 #4052031 未加载
评论 #4052414 未加载
grakic将近 13 年前
Hey, you can create new maze puzzles for your fun from the JavaScript console (WebKit Inspector, Firebug,...)! First create a new function to paint the custom map by pasting this code into the console: <a href="https://gist.github.com/2848451" rel="nofollow">https://gist.github.com/2848451</a><p>Next setup Maze.MAP matrix with value 1 for empty cell, 0 for path and 2/3 for start/finish positions.<p>Now run loadMazeMap() to load your new challenge ;)<p>Example: <a href="http://www.dodaj.rs/f/f/nM/4w3wop7u/custommaze.png" rel="nofollow">http://www.dodaj.rs/f/f/nM/4w3wop7u/custommaze.png</a>
dangrover将近 13 年前
The UI for this reminds me a lot of Scratch from MIT.
评论 #4051115 未加载
评论 #4050583 未加载
评论 #4052545 未加载
评论 #4051588 未加载
评论 #4052459 未加载
评论 #4050597 未加载
majke将近 13 年前
This seems to be done by an extraordinarily smart guy - Neil Fraser. He's behind "google-diff-match-patch" [1] project, which is AFAIK the machinery behind realtime collaboration on google docs.<p>Definitely worth watching.<p>[1] <a href="http://code.google.com/p/google-diff-match-patch/" rel="nofollow">http://code.google.com/p/google-diff-match-patch/</a>
评论 #4056513 未加载
评论 #4050735 未加载
ArekDymalski将近 13 年前
I don't understand. 1st it was part of AppInventor lab experiment. Google closed it in December and MIT took it over. Now it's back? Why?
评论 #4050946 未加载
lifthrasiir将近 13 年前
I should note that the appearance of Blockly is very similar to App Inventor[1]. It seems that visual programming languages with imperative and sequential semantics converge to one direction: "blocky" combining core primitives and custom primitives. In this sense I think it's THE future of domain-specific languages.<p>[1] <a href="http://www.appinventor.org/" rel="nofollow">http://www.appinventor.org/</a>
评论 #4054502 未加载
xarien将近 13 年前
I noticed something interesting and disturbing after reading some of the answers: people are more concerned with the length of the code rather than the optimal solution (no extra turns / backtracking). This reminds me of interviewing at MS about 12 years ago and all they cared about was the ability to write recursive code.<p>IMO, yes, elegant code is fantastic, but don't lose track of why we write code in the first place.<p>Edit: consolidating from post below.<p><a href="http://imgur.com/Nvy8u" rel="nofollow">http://imgur.com/Nvy8u</a><p>Here's a minimal solution with optimal logic (for this map) without hard coding. It also ensures that there is a forward step in every iteration of the while loop.<p>Basically it's just an order of precedence:<p>Turn right &#62; turn left &#62; go straight
评论 #4052386 未加载
评论 #4055543 未加载
评论 #4052321 未加载
arturadib将近 13 年前
Quick feedback: Would be great if the front page included some demos already built so we could have a better idea of what the final code looks like.
评论 #4050814 未加载
metamatt将近 13 年前
The puzzle-piece representation of structure is neat, but at a 2-minute glance it seems not to scale to real complexity.<p>One of the big ideas in programming is abstraction/modularity/reuse, and I don't see how that fits in here.<p>(I found the "procedure" block, but I don't see anything that fits inside it other than "break out of loop", which doesn't make any sense. And I don't see how to call the procedure.)<p>So I find myself looking at the samples everyone's demonstrating here and finding they're harder to read than real well-organized code.
th0ma5将近 13 年前
I like the comment in the Maze demo's javascript:<p><pre><code> /** * Execute the user's code. Heaven help us... */</code></pre>
agf将近 13 年前
<a href="https://imgur.com/VBsht" rel="nofollow">https://imgur.com/VBsht</a><p><pre><code> while (true) do if not (wall to the left) then (turn left) while (wall ahead) do (turn right) (move forward) </code></pre> This uses the general maze-solving logic of following the outer wall in one direction until you find the exit. It never turns then turns back or runs into a wall.
评论 #4051405 未加载
评论 #4052408 未加载
exDM69将近 13 年前
Notice how statement blocks are different shape than expression blocks. That's my favorite feature of this language.
antidoh将近 13 年前
After I placed <i>turn left</i> after <i>move forward</i>, what was my first instinct? Same as yours, I wanted to right-click <i>move forward</i> and place the copy after <i>turn left</i>.
grakic将近 13 年前
Can this program be made any shorter? <a href="http://www.dodaj.rs/f/1K/vW/2gLz63rl/blockly.png" rel="nofollow">http://www.dodaj.rs/f/1K/vW/2gLz63rl/blockly.png</a>
评论 #4052185 未加载
评论 #4050587 未加载
评论 #4050968 未加载
评论 #4050669 未加载
评论 #4050687 未加载
评论 #4051267 未加载
评论 #4050638 未加载
评论 #4050917 未加载
评论 #4050596 未加载
评论 #4050683 未加载
draegtun将近 13 年前
Reminds me of Sprog - <a href="http://sprog.sourceforge.net/" rel="nofollow">http://sprog.sourceforge.net/</a><p>Back in the day I was looking at Sprog for some client-facing project so probably worth looking back at it again. Here's a nice example of <i>Data Munging with Sprog</i> - <a href="http://www.perl.com/pub/2005/06/23/sprog.html" rel="nofollow">http://www.perl.com/pub/2005/06/23/sprog.html</a>
评论 #4052463 未加载
iandanforth将近 13 年前
Two feature requests:<p>As evidenced by this thread a 'Share' button would be great.<p>I'd love to be able to duplicate blocks by shift-click-n-drag.
xtreme将近 13 年前
Definitely needs an easy way to share programs. Taking screenshot and hosting it is not elegant at all!
kisielk将近 13 年前
This past weekend at the Vancouver Polyglot Conference there was a session with the author of Waterbear (<a href="http://waterbearlang.com/" rel="nofollow">http://waterbearlang.com/</a>) that got a fairly good turnout. It looks remarkably similar.
science_robot将近 13 年前
I can't seem to find the end condition for the Maze demo. There is no 'goal_reached?'
评论 #4051096 未加载
评论 #4050524 未加载
outworlder将近 13 年前
Looks like s-expressions to me.
评论 #4070539 未加载
richwhite将近 13 年前
Waterbear still has my vote for generating Javascript with the block based coding metaphore<p><a href="http://waterbearlang.com" rel="nofollow">http://waterbearlang.com</a>
jpalomaki将近 13 年前
This could become pretty interesting, especially if there is a platform aspect. Meaning I could easily extend this with my own elements and commands.<p>I can see some use for example in one application where we are importing data from other systems. Something like this could be used to create a quite nice user interface for creating simple programs that would manipulate and filter the incoming data.
misnome将近 13 年前
I like it a lot, and look forward to trying it out on my girlfriend to see how a non-coder responds to it.<p>Whilst working out the while loop however, I put the code to loop outside the block instead of inside, thereby making an infinite loop. Now the Chrome browser window is completely unresponsive, and won't even close, so it seems I have to kill chrome to get rid of it.<p>Other than that, cool!
评论 #4052823 未加载
sunwatcher将近 13 年前
I've always thought it would be cool to have a backend environment similar to labVIEW (but faster!). I use labview in my research and it is the best solution I've found for encouraging / allowing for code re-use. This Google Blockly, to some extent, seems to be heading that way - I'm looking forward to seeing how it develops.
prohan将近 13 年前
I'm surprised about the negative criticism. Looks like it would be a great teaching tool for non-computer programmers.
评论 #4051385 未加载
评论 #4050932 未加载
dxbydt将近 13 年前
fizzbuzz: <a href="http://i.imgur.com/QkLdz.png" rel="nofollow">http://i.imgur.com/QkLdz.png</a>
评论 #4055416 未加载
greggman将近 13 年前
Cool beans.<p>My suggestion based on no evidence what-so-ever is that I'd like to see something like this in a richer environment.<p>To give a bad example, VB. The original VB had forms (maybe it still does). You'd make a form. Double click the button and add code for "onclick" basically. I guess maybe that was inspired by Hypercard.<p>In any case it was really easy to see how to make a useful program because of the structure a form plus code snippets gave. If those code snippets were Blockly that might be better for learning.<p>A maybe better example is Unity3D. You add a 3d object, attach a Script and start editing code to move that object by supplying an Update() function or something along those lines. Maybe a Step() where you can define state change code snippets?<p>All I'm saying is a language like Blockly that removes the syntax errors, attached to a larger framework (games, graphics, or webapps), seems like it would make it far more approachable. You could actually make something useful or fun in a less steps.
评论 #4052996 未加载
michaelkscott将近 13 年前
Looks good, but I just crashed my chrome after putting a "repeat while&#62;and" block in between one of the move functions. Might want to watch out for new users accidentally crashing their browsers while trying to do something innocent.
bryanjclark将近 13 年前
I remembered a trick about mazes: if you keep your hand on the right wall, you'll eventually reach the end of the maze (assuming that the beginning and end share a contiguous wall)<p><a href="http://imgur.com/i2uOj" rel="nofollow">http://imgur.com/i2uOj</a><p>Fun puzzle!
评论 #4053121 未加载
hoodoof将近 13 年前
Love this idea for teaching kids. Reminds me of the visual programming in Click N Create / Multimedia Fusion / Games factory which was/is very advanced and powerful.<p>Given sufficient resource and polish something like this could be awesome.
评论 #4052365 未加载
olalonde将近 13 年前
Weird, I'm getting redirected here (even in incognito mode): <a href="https://www.google.com/accounts/CookieMismatch" rel="nofollow">https://www.google.com/accounts/CookieMismatch</a>
jasonkostempski将近 13 年前
Wall follower for the maze: <a href="http://imgur.com/w8xoQ" rel="nofollow">http://imgur.com/w8xoQ</a><p>I'd love to do Trémaux's algorithm if they'd add the full list of block types to the maze.
Iv将近 13 年前
I want something to code on my smartphone, without having to type more than is necessary. I expected this kind of thing to arrive. I hope they become more than a little toy.
评论 #4053126 未加载
minikomi将近 13 年前
Would have been cool of them to make it touch event friendly .. Seems like it would be a good fit for touchscreen logic noodling
评论 #4050889 未加载
postfuturist将近 13 年前
7 blocks has to be the shortest solution, right? <a href="http://imgur.com/r50yY" rel="nofollow">http://imgur.com/r50yY</a>
评论 #4052657 未加载
评论 #4052883 未加载
dave5104将近 13 年前
Did solving the maze remind anyone of Karel from Stanford's CS106A? :D Ah the memories.
ctdonath将近 13 年前
No way to save programs! Need either a text-to-Blockly importer, or use Google Drive.
kpennell将近 13 年前
Very cool, it has already been helpful it teaching me.
bawllz将近 13 年前
Noooooo they finished it before I did =(
markbaker将近 13 年前
google blockly isn't new. it was obviously inspired by www.waterbearlang.org
stewie2将近 13 年前
I need "comment" block.
评论 #4051122 未加载
pwpwp将近 13 年前
I ♥ it.
duckduckgouser将近 13 年前
Another language that creates javascript?
评论 #4052122 未加载