News for hackers. Stuff that matters.
Re:The Svelte Compiler Handbook by IshKebab on Sunday April 05, 2020 @05:11AM (#22784638)
The problem with Svelte is it doesn't support Typescript. You pretty much need that on any reasonable size project unless you are happy to spend your life tracking down runtime bugs. Vue has a similar problem (it sort of supports Typescript, but not properly and templates aren't type checked).

I've not used Elm so maybe that is better. React has good support for type checking. I would use that.

Re:The Svelte Compiler Handbook by untog on Sunday April 05, 2020 @09:45AM (#22785508)
I’ve had success with extracting as much logic as I can out of .svelte files and putting them in .ts and importing. At this point the JS logic in my svelte files is almost exclusively view lifecycle stuff. It’s not perfect but it works well enough for me, and I prefer the output to what I’d get with React.
Re:The Svelte Compiler Handbook by orange8 on Sunday April 05, 2020 @06:01AM (#22784815)
> Typescript. You pretty much need that on any reasonable size project unless you are happy to spend your life tracking down runtime bugs

I'd say it depends on your teams skill set and level of disciple. The best defence against a buggy codebase isn't a programming language or framework, its good all fashioned discipline.

Re:The Svelte Compiler Handbook by CapsAdmin on Sunday April 05, 2020 @07:38AM (#22785072)
I think we all agree on this, but we don't all agree that "just be disciplined" works in practice.

"Just don't write bugs", "just write perfect code", etc

Given that you and your team has all the discipline you need, you could still argue that type checking the codebase in your head is time consuming and is better spent on higher level concepts.

A typesystem can get in the way and slow down development if it's too strict of course, but I feel typescript does a good job of keeping it optional enough.

There is no clear answer here, but at least refactoring is much easier and safer given that your types are sound.

Re:The Svelte Compiler Handbook by orange8 on Sunday April 05, 2020 @09:01AM (#22785371)
> "Just don't write bugs", "just write perfect code", etc

You are putting words in my mouth. I do not believe that you can write perfect code or avoid bugs. Just like I do not believe there is this perfect programming language or framework out there that magically creates clean code.

> you could still argue that type checking the codebase in your head is time consuming

This again, depends on the particular history and skill-set of your team. For example, TypeScript fits very well if you are familliar with C#, while CoffeeScript fits very well to those comfortable with python/ruby, ClojureScript for those who like clojure, ESLint for those comfortable with JS ... etc

Re:The Svelte Compiler Handbook by CapsAdmin on Tuesday April 07, 2020 @08:34AM (#22802567)
> I do not believe that you can write perfect code or avoid bugs.

I don't think anyone (including you) does. I don't think typescript pretends to be a perfect programming language that magically creates clean code either, but I think it gets us closer to that unrealistic goal.

> This again, depends on the particular history and skill-set of your team. For example, TypeScript fits very well if you are familiar with C#.

I very much disagree with this.

If you want to compare Typescript with another language, you have to remember that its typesystem is optional. So all you are left with basically Javascript. How much of the typesystem you want to use is up to you and your team.

Personally I try to let typescript infer the types as much as possible. I only explicitly annotate function arguments and foregin data. Sometimes there are cases where the typesystem won't work. Usually it's because I want to dynamically create something instead of verbosely defining everything. If the dynamic way is easier to maintain I choose that way and may lose some type information. (often you can tell the typesystem that "this dynamic blob" results in "this explicit type" though)

I'm not very fond of C# but I enjoy Typescript. I think the reason I don't like C# is because it forces you to make classes of everything which to me adds a lot of friction.

Re:The Svelte Compiler Handbook by orange8 on Wednesday April 08, 2020 @07:09AM (#22811824)
TS may compile down to JS, but that does not make it the same language. TS done the proper idiomatic TS way is just very different from JS done the proper functional + dynamic way. How you structure your code using a dynamic, functional language should be very different from how you structure your code in a static, object oriented language. If your code structure looks more or less just the same between the two, then you are doing one of them wrong.

> you have to remember that its type system is optional

Doesn't opting out of the type system defeat the purpose of using TYPE-script in the first place?

Re:The Svelte Compiler Handbook by CapsAdmin on Thursday April 09, 2020 @08:14AM (#22821794)
> TS done the proper idiomatic TS way is just very different from JS done the proper functional + dynamic way.

Where do you get the idea that Typescript code should be structured like a static object oriented language? Is it because it's a Microsoft product?

Letting Typescript try and figure out the types while coding in a "dynamic and functional way" is what works best for me. Is this wrong?

Re:The Svelte Compiler Handbook by orange8 on Friday April 10, 2020 @09:42AM (#22832890)
Re:The Svelte Compiler Handbook by madeofpalk on Sunday April 05, 2020 @05:45PM (#22789007)
As a “life long” web/JavaScript developer, ESLint is nowhere near comparable to Typescript. One is a language, and the other is an (overused and over configured) linter. They’re two different things.

I’m no C# developer, but the only way it is familiar to Typescript in the sense that it is a typed language.

Typescript is a superset of JavaScript, and is remarkably close. If you know JavaScript, typescript will be exceptionally similar because it’s literally the same, just with types added on top.

Re:The Svelte Compiler Handbook by orange8 on Sunday April 05, 2020 @06:04PM (#22789121)
I have worked with two compile to JS languages, CoffeeScript and TypeScript.

> One is a language, and the other is an (overused and over configured) linter.

You could also say that one is an extremely opinionated linter and the other is just a linter.

Re:The Svelte Compiler Handbook by madeofpalk on Monday April 06, 2020 @08:49AM (#22793226)
No, I would not say that a type system is an "extremely opinionated" linter because TypeScript is about proving correctness and safety, not enforcing style guidelines.

A linter and a type system are two extremely different things. The only thing they have in common is that they statically analyse code.

Re:The Svelte Compiler Handbook by branko_d on Sunday April 05, 2020 @11:17AM (#22786054)
It's not just about bugs. Static typing is crucial for productivity whenever the codebase overflows your brain's working memory.

Navigating through code, refactoring, or simply figuring out what to pass as function input can become a challenge in the absence of types.

Re:The Svelte Compiler Handbook by smnplk on Monday April 06, 2020 @12:03AM (#22790818)
That's why god invented comment blocks. But some people view them as code smell, which i find very strange. And no, good naming is not always enough.
Re:The Svelte Compiler Handbook by IshKebab on Wednesday April 08, 2020 @04:07AM (#22810961)
So you're saying it's a good idea to write what your types are in your code, but rather than writing them in a form that can be automatically checked by a computer and used for code completion and refactoring, you prefer to write them in a comment?
Re:The Svelte Compiler Handbook by smnplk on Monday April 13, 2020 @01:00PM (#22857578)
No, I said no such thing. If you happen to be in a dynamic environment, then yes, I see no foul in describing inputs to a function inside a comment above function declaration. Use comments to describe your intents on non trivial parts of your code. There is no amount of code readability that will help your colleague, if she doesn't understand your thought process at the time of writing the code.
Re:The Svelte Compiler Handbook by michaelcampbell on Friday April 10, 2020 @09:23AM (#22832725)
"not always enough" is still better than "none". This feels like a classic "good being the enemy of the perfect" issue.
Re:The Svelte Compiler Handbook by bambataa on Sunday April 05, 2020 @06:43AM (#22784915)
Don’t need to catch bugs if you just don’t write them! taps head.

It is still worthwhile imo to have something that catches mistakes even great people make.

Re:The Svelte Compiler Handbook by orange8 on Sunday April 05, 2020 @07:41AM (#22785082)
I completely agree. That something is a linter, of which TypeScript is just one of the many options available. This whole idea of you cannot write a big app in JS is just peddled by those who do not understand, or hate JS. A good linter, proper programming practices, discipline will get you there. Anytime someone peddles a language or framework as a magic bullet to clean code, they're either selling you some snake oil or have drunk too much of some koolaid, imho.
Re:The Svelte Compiler Handbook by giantDinosaur on Sunday April 05, 2020 @08:19AM (#22785230)
This is the kind of attitude that has resulted in a million code vulnerabilities in C because the idea that it's inherently unsafe is just an idea 'peddled by people unskilled in its application' (to re-express nicely). It's the kind of attitude which will ignore the many inconsistencies in languages which were the result of historical accident instead of good design because it's just a blind acceptance of the way things turned out to be rather than what they _could_ be. Many who go on about 'discipline' are often creating error prone applications and, ironically, peddling 'discipline' as that very magic bullet to cure all ills.

I don't know if I've even seen discipline defined beyond some self-referential 'avoid doing these bad things that our language/environment allows by knowing that they're bad before you make the mistakes that show you they're bad'. Do developers just shrug and accept it as a fundamental design constraint to good programming languages when their booleans add with their integers and concatenate with their strings and give essentially random results? Do they not wonder: is there a system, more fundamental than linting, which can solve many of these issues in a general case?

Re:The Svelte Compiler Handbook by orange8 on Sunday April 05, 2020 @08:33AM (#22785275)
The idea that "A good linter, proper programming practices, discipline will get you there" has resulted in "a million code vulnerabilities in C" !!

That is a surprising jump in cause-and-effect logic right there. I do not code any C, but I assure you if I did I'd consider it part of proper programming practice and discipline to write code that avoids those exact vulnerabilities you suggest. But, picking a whole new programming language instead is just lying to yourself, because there is no perfect programming language.

None! Zero. Not one, no matter how much in love you are with it. They all have their warts, strengths and weaknesses, and if you are not aware of any in your language of choice, and actively working to avoid and mitigate against them (aka discipline and best practice) then you have fallen prey to exactly what I was talking about: the idea that a framework or language is a magical silver bullet to writing clean code. If you thought I was saying JS (or C, TypeScript, Haskel etc) is this perfect, wonderful language, you completely misunderstood me.

Re:The Svelte Compiler Handbook by nmfisher on Sunday April 05, 2020 @09:23AM (#22785441)
> I do not code any C, but I assure you if I did I'd consider it part of proper programming practice and discipline to write code that avoids those exact vulnerabilities you suggest.

And yet all of those vulnerabilities came from hundreds of developers who shared the same misplaced confidence in their own abilities.

It's the same as hospitals. You can't just say "who needs checklists? Surgeons and assistants should be disciplined enough to not make mistakes in the first place!".

In an ideal world they would be, but in this world, they're not and never will be.

Not being able to admit this is how you end up with surgery on your left knee when it was meant to be your right.

Accept that no-one is 100% perfect, 100% of the time - let alone you - and mould your development around these (very human) failings. "Disciplined programming" will never be as safe as "disciplined programming with guard-rails built into the language". Weigh up the trade-offs - sometimes the performance gain is worth the risk, sometimes it's not.

Re:The Svelte Compiler Handbook by orange8 on Sunday April 05, 2020 @06:20PM (#22789223)
> And yet all of those vulnerabilities came from hundreds of developers who shared the same misplaced confidence in their own abilities.

This is a good example of a straw man argument. A comment about a programming language or framework not being a silver bullet to clean code has suddenly been twisted into a comment about developers with misplaced confidence in their abilities. How exactly does using best practice in and discipline equate to overconfidence?!

good practice and discipline ≠ misplaced confidence

Re:The Svelte Compiler Handbook by jolux on Sunday April 05, 2020 @06:28PM (#22789276)
You appear to assume that applying good practice and discipline is a route to eliminating these problems rather than mitigating them.
Re:The Svelte Compiler Handbook by orange8 on Sunday April 05, 2020 @06:45PM (#22789361)
> You appear to assume

I like your choice of words, but no. I disagree with that assumption.

Re:The Svelte Compiler Handbook by jolux on Sunday April 05, 2020 @07:06PM (#22789492)
Well, in that case, I will observe that static type systems and memory safety do eliminate the problems of ill-typed programs and memory unsafe programs, and that these are highly desirable properties for a lot of systems.
Re:The Svelte Compiler Handbook by orange8 on Sunday April 05, 2020 @07:32PM (#22789633)
And I will observe, once again, that all that means nothing without best practice and discipline.
Re:The Svelte Compiler Handbook by jolux on Sunday April 05, 2020 @09:24PM (#22790170)
It doesn't mean nothing without those things though. It means exactly the same whether or not you follow best practices or have discipline, that's the entire point. It will not ensure your code is good, it will merely ensure it does not have those problems.
Re:The Svelte Compiler Handbook by orange8 on Sunday April 05, 2020 @10:03PM (#22790311)
If its about clean code, all that means nothing without discipline and good practice. Clean code is something humans do, not linters, compilers or languages.
Re:The Svelte Compiler Handbook by jolux on Sunday April 05, 2020 @10:21PM (#22790398)
Have you written a significant amount of C? I ask this because you said you don't write any of it in a comment in which you suggested its problems could be avoided by following best practices and being disciplined. There are a set of problems that languages have that just cannot be solved by humans adopting better discipline or best practices. C's type system is unsafe, and its memory handling is an adjacent and related problem. Tools like Valgrind exist and they are considered best practices when writing C, but they do not claim and cannot hope to make it memory safe. Fixing that problem requires language-level intervention, and this has been solved most of the time with better static type systems. Anyone who writes a lot of C will tell you this, it is an inherent pitfall of the language's design and one to be avoided when designing new languages.
Re:The Svelte Compiler Handbook by jolux on Sunday April 05, 2020 @02:28PM (#22787355)
You're making a false dichotomy here. There's a lot of light between something being a magical silver bullet that solves all your problems and every programming language being equally bad. If that weren't the case we would probably have never progressed from unstructured programming.

In general the greatest progress in software engineering practice at the level of programming languages is made when something that was previously left up to human discipline is made automatic so we don't have to struggle with it anymore: memory safety, type checking, and at the beginning, returning from subroutines at a structured location back to a structured location instead of control flowing wildly throughout a program with jumps.

Yes, it's theoretically possible to do all these things well without the assistance of a computer, but in practice, it's more work than any human can handle. The problems that newer programming languages have are an argument for fixing those problems, not reintroducing ones we've already solved.

Re:The Svelte Compiler Handbook by orange8 on Sunday April 05, 2020 @06:13PM (#22789182)
> Typescript. You pretty much need that on any reasonable size project unless you are happy to spend your life tracking down runtime bugs.

This is the original grandparent comment I was responding to. To me, this sounds like the belief that only one language can solve a problem which I disagree with. TypeScript is not a silver bullet. They are all just tools. Pick the ones that work for you, but do not go and start preaching about your toolset being the one and only true path to code nirvana.

> ...and every programming language being equally bad.

I simply did not say that.

Re:The Svelte Compiler Handbook by jolux on Sunday April 05, 2020 @06:27PM (#22789267)
>I simply did not say that.

No, you're right, what you said is that there is no perfect programming language, and that they all have warts and problems. On that I agree with you, but in this case you seem to be using it to suggest that the language doesn't matter and it's all or even mostly a question of personal discipline, which I completely disagree with. Correct me if I'm wrong.

>To me, this sounds like the belief that only one language can solve a problem which I disagree with.

I disagree with that interpretation too, but the argument they were actually making was about static type systems, as evidenced by their comment about React and the importance of type checking. TypeScript is merely the most popular typed JavaScript variant.

>TypeScript is not a silver bullet.

Sure, I would actually prefer a much stronger type system than it provides, but it's certainly better than nothing.

>They are all just tools.

Sure, but some tools work better than others.

>Pick the ones that work for you, but do not go and start preaching about your toolset being the one and only true path to code nirvana.

I didn't see the grandparent preaching about "code nirvana" at all. They were making a pretty typical argument about the outsize effectiveness of static types in large codebases. It's entirely possible that programming in a large codebase with TypeScript sucks, but that programming in a large codebase with JavaScript sucks more. There is no perfect programming languages, but there are definitely better ones.

Re:The Svelte Compiler Handbook by orange8 on Sunday April 05, 2020 @06:44PM (#22789355)
I get it. You like TypeScript, it works for you. You like and firmly believe in static types, also great. No one is asking you to stop using them, or suggesting that they are bad. They are all just tools, use the ones that work for you. Personally, I do not need TypeScript, ESlint gets me there, but then again I'm not you. Just like I'm not going to assume your code is completely perfect and bug free because you use tool X, you should not assume mine is bad and buggy because I use tool Y.
Re:The Svelte Compiler Handbook by jolux on Sunday April 05, 2020 @07:05PM (#22789485)
I’m not assuming it’s bad and buggy code. My day job is writing Elixir, albeit with full type spec coverage, and the code is fine. But that’s enabled by an extensive test suite, as well as type specs. Do we need these things, strictly speaking? No. But we don’t really need any of the tools we build and use, yet we build them because they make certain things easier and more reliable.

My code is not perfect and bug free when I write it in a strongly typed language, however it is guaranteed to be free of type errors provided the type system is sound. That level of confidence in types is just not possible in a dynamic language.

Re:The Svelte Compiler Handbook by orange8 on Sunday April 05, 2020 @07:35PM (#22789649)
> it is guaranteed to be free of type errors provided the type system is sound

Give me an example of a sound type system.

Re:The Svelte Compiler Handbook by jolux on Sunday April 05, 2020 @09:45PM (#22790248)
STLC
Re:The Svelte Compiler Handbook by orange8 on Sunday April 05, 2020 @10:42PM (#22790505)
> STLC

Software Testing Life Cycle? That is not a type system, that is a software development methodology. Thought you'd mention atleast TypeScript or Elixir, but no, you went for the a whole software development methodology. Which kind of puts you in a bind now, since you also said: "..it is guaranteed to be free of type errors provided the type system is sound". So where does that leave us if you cannot confidently give an example of a sound type system?

> That level of confidence in types is just not possible in a dynamic language.

Not possible with static languages either, unless ofcourse you use the whole "Software Testing Life Cycle". Do you know what I like most about STLC? It advocates what I have been saying all along: discipline and best practice!!!

And you can use STLC with dynamic languages to and get the same benefits.

Re:The Svelte Compiler Handbook by jolux on Sunday April 05, 2020 @11:04PM (#22790616)
> Software Testing Life Cycle?

No.

Re:The Svelte Compiler Handbook by orange8 on Monday April 06, 2020 @02:28AM (#22791331)
> STLC

>> Software Testing Life Cycle?

> No

Ok. Since you were saying things like "..that’s enabled by an extensive test suite, as well as type specs" I assumed it must be something to do with testing. Must be a programming language I've never heard about then.

Re:The Svelte Compiler Handbook by IshKebab on Sunday April 05, 2020 @09:58AM (#22785554)
Yep, just like the best defence against dying in a car crash isn't a seatbelt or airbags, it's good old fashioned being awesome at driving like me.
Re:The Svelte Compiler Handbook by madeofpalk on Sunday April 05, 2020 @08:38AM (#22785290)
Typescript is not a product for teams of low skill of disciple, and it's pretty insulting to suggest it is.
Re:The Svelte Compiler Handbook by orange8 on Sunday April 05, 2020 @08:52AM (#22785331)
That is certainly not what I was suggesting.
Re:The Svelte Compiler Handbook by madeofpalk on Sunday April 05, 2020 @03:12PM (#22787727)
You literally said "[Whether you need Typescript or not] depends on your teams skill set and level of disciple".
Re:The Svelte Compiler Handbook by orange8 on Sunday April 05, 2020 @06:24PM (#22789249)
level of discipline ≠ low discipline
Re:The Svelte Compiler Handbook by jkaptur on Monday April 06, 2020 @02:38AM (#22791371)
I think you mean “old fashioned”... which goes to show that even skilled, disciplined, knowledgeable folks can make simple mistakes. When the stakes are high, it’s important to use tools to augment human judgement.
Re:The Svelte Compiler Handbook by michaelcampbell on Friday April 10, 2020 @09:22AM (#22832712)
I'd say Elm has support for types, yes =D
Re:The Svelte Compiler Handbook by 0az on Sunday April 05, 2020 @05:26PM (#22788868)
IIRC, Vue 3 uses Typescript.