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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Leaving Python for JavaScript

81 点作者 jgalvez超过 7 年前

20 条评论

ageitgey超过 7 年前
So a person who writes web apps prefers JS over Python. Cool. Pick the right tool for the job. If your job is writing client-side-heavy web apps that share code between the client and server, then JS might be a better choice than Python.<p>Look, writing programs that respond to HTTP requests with HTML is not rocket science. You can do it in JS, Python or Ruby and be very productive. If you hate yourself, you can do it in Java, Go or whatever else and trade server performance for development speed. If you really hate yourself (or are Amazon circa 2004), you can write your whole website as a C++ static binary.<p>My theory is that the endless proliferation of JS libraries, frameworks and language revisions are because lots of smart and talented developers are employed to build websites - but building websites is just not that technically interesting, so they express their creativity by creating new tools, frameworks, package managers and ES revisions. It&#x27;s a symptom of boredom.<p>But my one bit of career advice would be don&#x27;t &quot;Leave X for Y.&quot; Don&#x27;t tie your livelihood and career to a single X or Y. Learn how to use a variety of tools and pick the best one for each job. Any big project will require using a few different tools and really valuable developers are the ones who can navigate that entire landscape intelligently.
评论 #15100938 未加载
评论 #15100425 未加载
monkmartinez超过 7 年前
I started programming in JS then moved to Python. It seems like JS has become very, very complicated. I look at his post and I am lost... I remember Knockout.js and Node in the v0.8 days.<p>I mean look at this:<p><pre><code> dotenv (lets you load the environment from an .env file), axios (HTTP client library), cheerio (HTML parsing library), bcrypt (password hashing), co-body (HTTP body parser), co-busboy (HTTP multipart parser), jsonwebtoken (JWT generator), koa-jwt (JWT middleware), koa-router, koa-sslify, vue-no-ssr and source-map. </code></pre> What the hell is all that? I am not saying he is wrong... I am just saying that I don&#x27;t have the capacity to play in that playground. I am also asking if any of those libraries will be around in a year?
评论 #15099734 未加载
评论 #15099790 未加载
评论 #15103760 未加载
评论 #15101375 未加载
评论 #15099768 未加载
评论 #15099800 未加载
Walkman超过 7 年前
&gt; there&#x27;s no acceptable way to pass a function body to another in Python.<p>There are sentences which are telling a huge incompetence about the person using these.<p>This sounds the same story to me as &quot;We used tech X, but X is shit&#x2F;can&#x27;t do something so we switched to Y, and Y is awesome and fast.&quot; Where the person switching was just incompetent with X but it would have been perfectly solvable and they just do a totally different thing with Y.<p>In the specific &quot;passing a function&quot; case, yes, it&#x27;s impossible to pass only a function body, but I think it&#x27;s impossible to do in JavaScript also? (correct me if I&#x27;m wrong), because you pass in function. You can do the same in Python by defining a function in the same scope and passing that in. If you don&#x27;t like that, it&#x27;s just one opinion, not necessarily good or bad. For example, I find it ugly and difficult to handle nesting this multiple times (defining another anonymous function inside an anonymous function) which is called &quot;callback hell&quot; if I understand right, but that&#x27;s just my opinion also, because people seem to able to accept this hell. :)
评论 #15099927 未加载
评论 #15099883 未加载
评论 #15099863 未加载
评论 #15101006 未加载
评论 #15100660 未加载
rdudekul超过 7 年前
A lot of innovation happened in JavaScript space over the past few years and yet the learning curve is high. I prefer to use Python for Data Analysis, Data Transformations &amp; Machine Learning. For web applications, Node&#x2F;Express + React&#x2F;Vue seems to work better.
评论 #15100279 未加载
abuckenheimer超过 7 年前
&gt; So with JavaScript you&#x27;ve got arrow functions, the method shorthand definition syntax, the spread operator, destructuring assignments, all functional Array methods and async functions.<p>This confuses me quite a bit, there are nuanced differences between these ideas in the two languages but at the surface these are things that very much exist in both languages<p><i>arrow functions:</i><p><pre><code> (x,y) =&gt; { x + y } </code></pre> vs.<p><pre><code> lambda x,y: x + y </code></pre> method shorthand definition:<p><pre><code> MyObj = { foo(x,y) { return x + y } bar(x,y) { return x * y } } </code></pre> vs.<p><pre><code> class MyObj: foo(self, x, y): return x + y bar(self, x, y): return x * y </code></pre> <i>spread operator:</i><p><pre><code> function add(x,y) { return x + y } add(...[1,2])</code></pre> vs.<p><pre><code> def add(x, y): x + y add(*[1,2]) </code></pre> <i>destructuring:</i><p><pre><code> [a, b, ...rest] = [10, 20, 30, 40, 50]; </code></pre> vs.<p><pre><code> a, b, *rest = [10, 20, 30, 40, 50] </code></pre> <i>functional array methods:</i><p><pre><code> forEach([&quot;Wampeter&quot;, &quot;Foma&quot;, &quot;Granfalloon&quot;], print); </code></pre> vs.<p><pre><code> list(map(print, [&quot;Wampeter&quot;, &quot;Foma&quot;, &quot;Granfalloon&quot;])) </code></pre> <i>async methods:</i><p><pre><code> function resolveAfter2Seconds(x) { return new Promise(resolve =&gt; { setTimeout(() =&gt; { resolve(x); }, 2000); }); } async function add1(x) { var a = resolveAfter2Seconds(20); var b = resolveAfter2Seconds(30); return x + await a + await b; } add1(10).then(v =&gt; { console.log(v); &#x2F;&#x2F; prints 60 after 2 seconds. }); </code></pre> vs.<p><pre><code> async def resolve_after_2_seconds(x): await asyncio.sleep(2) return x async def add1(x): a = resolve_after_2_seconds(20) b = resolve_after_2_seconds(30) return x + await a + await b loop = asyncio.get_event_loop() loop.run_until_complete(add1(10)) </code></pre> There&#x27;s a lot of fun differences between the origins of these features and how they work but the sentence to me doesn&#x27;t quite to the idea of &quot;Leaving Python for JavaScript&quot; justice
dharness超过 7 年前
Why is all the actual content on the far right side of the page? Even more interesting given that you specialize in UI&#x2F;UX.
评论 #15100568 未加载
评论 #15100321 未加载
_greim_超过 7 年前
With async&#x2F;await now landing in mainstream engines, Koa instead of Express, the new Turbofan+Ignition optimization pipeline &quot;evening out&quot; V8&#x27;s performance characteristics, and ES6 enjoying reasonably broad support, I feel like JS is now crossing a threshold into being not a completely sucky programming experience, which is a sentiment this article echoes.<p>I&#x27;m probably being overly optimistic, but I look forward to a future where a &quot;naked JS&quot; movement rises up, similar to &quot;vanilla JS&quot;, but rebelling against tooling complexity instead of jQuery bloat, in which your website&#x27;s &#x2F;js&#x2F; folder contains pretty much exactly what&#x27;s in git.
评论 #15103775 未加载
dagenleg超过 7 年前
&gt; there&#x27;s no acceptable way to pass a function body to another in Python.<p>What. Why would you ever want a function body as a string? What kind of vile sorcery are you doing? One can use inspect.getsourcelines in python if really pressed to, but I find it horrifying that javascript developers actually seem to require this functionality often.
评论 #15099436 未加载
评论 #15099417 未加载
评论 #15099381 未加载
评论 #15099512 未加载
jjnoakes超过 7 年前
I want to like JavaScript, but the type coercion land mines and the lack of a real numeric tower make me a little queasy. When I have to use JS I stick to the transpile-to-js languages mostly for those reasons.
评论 #15100085 未加载
yiransheng超过 7 年前
ES6+ javaScript in absorbed many great features from python: destructuring vs. tuple unpacking, spread (...) vs *args argument unpacking and generators. Many things I enjoyed in python are now also idiomatic javaScript. Only thing missing is function decorators:<p><pre><code> @connect(...) function StateLessComponent(props) { }</code></pre>
freecodyx超过 7 年前
I did the move but to GOLANG instead.<p>I think what is more important than the language it self, is the toolings and standard library.<p>every now and then you hear about a new framework, a lot of hype, which is not for big projects.<p>I think the wise thing is to move to golang
评论 #15099882 未加载
devnonymous超过 7 年前
&gt; So with JavaScript you&#x27;ve got arrow functions, the method shorthand definition syntax, the spread operator, destructuring assignments, all functional Array methods and async functions.<p>In language that pythonistas would grok:<p>Arrow functions: multiline lambda definitions<p>method shorthand definition syntax: class defined with only classmethods, or in other words a namespace<p>the spread operator: *args in functions<p>destructuring assignments: tuple unpacking... But also for creation of instances<p>all functional Array methods and async functions: functools and async... Plus a bit more<p>While most of this is good to know, I&#x27;d still stick with python for readability and maintainability purposes.
评论 #15101467 未加载
wolco超过 7 年前
If you started with php instead of python you would never have left.<p>Vue is a great language but php can offer more in the backend
kochandy超过 7 年前
Thanks for your article. It&#x27;s really helpful to hear about the technologies that have been used in actual projects&#x2F;production environments. I&#x27;d love to hear more about what diminished your excitement with ElementUI vs iView
评论 #15102257 未加载
yupyup超过 7 年前
When reading these &quot;Leaving X for Y&quot; I first think that maybe some people are unable to fluently use more than 1 language.<p>Seriously, professionality is being able to use the right tool for the job at hand.
metaphorm超过 7 年前
why is the sidebar on the left half the width of the page? I can hardly read the main content crammed into the right half.
deathanatos超过 7 年前
&gt; <i>the spread operator</i><p>How?<p>JS:<p><pre><code> var args = [0, 1, 2]; myFunction(...args); </code></pre> Python:<p><pre><code> args = [0, 1, 2] myFunctions(*args) </code></pre> A more complicated one:<p>JS:<p><pre><code> var args = [0, 1]; myFunction(-1, ...args, 2, ...[3]); </code></pre> Python:<p><pre><code> args = [0, 1] myFunction(-1, *args, 2, *[3]) </code></pre> As used in list building; JS:<p><pre><code> var parts = [&#x27;shoulders&#x27;, &#x27;knees&#x27;]; var lyrics = [&#x27;head&#x27;, ...parts, &#x27;and&#x27;, &#x27;toes&#x27;]; </code></pre> Python:<p><pre><code> parts = [&#x27;shoulders&#x27;, &#x27;knees&#x27;] lyrics = [&#x27;head&#x27;, *parts, &#x27;and&#x27;, &#x27;toes&#x27;] </code></pre> &quot;A better way to concatenate arrays&quot;; JS:<p><pre><code> var arr1 = [0, 1, 2]; var arr2 = [3, 4, 5]; arr1 = [...arr1, ...arr2]; </code></pre> Python:<p><pre><code> arr1 = [0, 1, 2] arr2 = [3, 4, 5] arr1 = arr1 + arr2 </code></pre> (Though the star notation works here too.)<p>I omit JS&#x27;s use of ... on objects; Python&#x27;s class system works differently — and IMO, more rigorously — than JS&#x27;s, making ... less sensible on Python objects. (Python focuses much less on passing around untyped key-value bags and more on strongly typed classes IMO; both are possible in both languages, but the idioms around them differ, and I think Python&#x27;s idioms tend more towards having a well defined class with well defined attributes, and not having just a bag of attributes, moreso than JS at least, and I feel that direction (well defined classes) leads to more robust code. In particular, it forces you into naming your concepts, and defining their set of attributes: a simplistic type definition.)<p>&gt; <i>all functional Array methods</i><p>Python has map, reduce, etc., as well as generator and list comprehensions which are often easier to use.<p>&gt; <i>async functions</i><p>Python and JavaScript have practically identical syntax in this area.<p>&gt; <i>there&#x27;s no acceptable way to pass a function body to another in Python</i><p>I find it very acceptable that if your function body is more complicated than an expression, that you&#x27;re forced to pull it out and name it, frankly. I think it does good things for fighting complexity, and this just isn&#x27;t something I worry about day to day while using Python. But I will concede that Python does lack a syntax for passing a function in an expression context.<p>(But I would also note JS&#x27;s screwed up named-function syntax; in Python:<p><pre><code> def foo(): # body </code></pre> is a valid statement. JS&#x27;s:<p><pre><code> function foo() { &#x2F;&#x2F; body } </code></pre> is <i>not</i> a valid statement, and can only appear in certain, particular contexts. In particular, the following is not valid JavaScript, though many implementations will do The Right Thing™, I&#x27;m told:<p><pre><code> if(true) { function foo() { &#x2F;&#x2F; body. } } </code></pre> [2])<p>&gt; <i>My code usually revolves around higher order functions, reduce(), map(), etc. I can&#x27;t remember the last time I wrote a regular for loop in JavaScript.</i><p>Because JS for a long time (until ES6&#x27;s for(… of …) syntax) lacked a for loop (the C style look, and for(… in …), do <i>not</i> count, as they do semantically different things), which is why you&#x27;re using forEach().<p>&gt; <i>arrow functions</i><p>The best thing about arrow functions is the sane binding of `this`, a problem notably absent in Python to begin with.<p>&gt; <i>[Python&#x27;s] class definition boilerplate is still hard to look at</i><p>This is sometimes true; I find the attrs[1] package helps greatly here for small, struct-like classes.<p>[1]: <a href="https:&#x2F;&#x2F;pypi.python.org&#x2F;pypi&#x2F;attrs" rel="nofollow">https:&#x2F;&#x2F;pypi.python.org&#x2F;pypi&#x2F;attrs</a><p>[2]: <a href="http:&#x2F;&#x2F;kangax.github.io&#x2F;nfe&#x2F;#expr-vs-decl" rel="nofollow">http:&#x2F;&#x2F;kangax.github.io&#x2F;nfe&#x2F;#expr-vs-decl</a>
ojhughes超过 7 年前
Poor misguided person
评论 #15100898 未加载
评论 #15101512 未加载
scriptkiddy超过 7 年前
Just in case the author is present in the thread:<p>Your blog is extremely difficult to read on wide screen monitors. The entire left 50% is basically just blank space. My suggestion is to make the left side maybe 20% width on desktop or less.<p>Also, regarding the article content:<p>There really aren&#x27;t any good reasons presented here about why you moved from Python to Javascript for back-end web development. It seems that you simply prefer Javascript semantics. There&#x27;s nothing wrong with that, but the title is misleading considering that the bulk of the article is actually about which JS tools you use on recent projects and not why you moved.<p>Also, could you clarify what you mean by<p>&gt; Also, there&#x27;s no acceptable way to pass a function body to another in Python.<p>Functions are first-class in python and can be passed as arguments to other functions. I&#x27;m not sure I understand what you mean with the above statement.<p>Cool to see someone else has been using Nuxt though.
评论 #15100062 未加载
评论 #15100252 未加载
评论 #15100173 未加载
holydude超过 7 年前
I am still learning to like Javascrip and its ecosystem. I do not think I would be able to invest time in transpile-to-js language (looking at you TypeScript). I really hate the evolving ecosystem, hyped libs &#x2F; frameworks and tons spaghetti new paradigms.
评论 #15101495 未加载