77
top 50 comments
sorted by: hot top controversial new old
[-] nous@programming.dev 24 points 1 year ago

Overall I agree with what the author says, though I have a few further thoughts:

One might argue that writing types are time consuming, and the bugs are not an issue when programmer can cover those cases with automated tests.

These two arguments contradict each other and together are an argument for static typing, not against. Which just shows how weak these arguments are.

but a more powerful type of inference that can actually infer the whole type of a function by analyzing the body of the function.

This bit I am not convinced by. Inferring the API of a function from its body makes it harder to see breaking changes when you refactor the body. It can be useful for internal private helpers, but IMO public APIs should be explicit about their signature.

Functional Programming

I would go one step further here. It should support OOP and procedural paradigms as well. No single programming paradigm is best suited to all problems. Sometimes a mixed approach is best. Any language that heavily leans oneway at the expense of the others limits itself to the problems it can best solve. I do admit the far too many languages lean too much towards OOP at the expense of functional style.

So it is easy to push for a functional style over OOP in new languages. But I would be weary of purely functional language as well.

[-] relative_iterator@sh.itjust.works 10 points 1 year ago

I don’t understand how types could be time consuming.

[-] nous@programming.dev 6 points 1 year ago

Some things are very easy to do in loosly typed languages - just as letting a function take a string or int, and then parsing that string into an int if a string was passed in. In a loosly typed language you can just call something like if typeof(input) but in a strongly typed language you often need a lot more boiler plate and extra wrapper types to say the function can only take an int or string - for instance in rust you might need to wrap them in a enum first or some how create a trait and implement that for each types.

This is quite a bit of extra upfront cost some of the time that really rubs people that are used to loosly typed languages the wrong way. So they think it is slow to work with types. But what they never seem to count is the countless hours you save knowing that when you read a value from something and pass it to a function that wants only an int, that the value is an int and you dont end up getting 2 + "2" = "22" and other suprising bugs in your program. Which results in less time debugging and writing tests for weird cases the compiler does not allow.

But all that extra time if often not counted as that is dissociated from the original problem at hand. And they are already used to this cost - people often notice a new cost, but don't notice a possibly bigger saving else where.

[-] wasted@programming.dev 4 points 1 year ago

I never understood this argument. If your function is supposed to take an int, then parse your string before calling it?

[-] nous@programming.dev 3 points 1 year ago

There are reasons you might want to, such as you are constructing something that has a few different ways to create it. Like maybe a date, can parse it from a string, pass in each bit as a separate argument, take in a Unix timestamp.

A lot of languages encourage this with constructors as you can often only have one.

IMO it is far better to just have different functions for each type you want to build something from like how it is done in rust.

But when you come from a language that encourages the opposite it can seem clunky to have to define separate functions for each. And it can take a while to accept the different way of working.

[-] JackbyDev@programming.dev 4 points 1 year ago

I agree, but I imagine dynamic type fans would say they don't understand why explicitly stating types can be helpful.

Optional typing is pretty useful, especially if the tooling is such that it catches most issues. I use Python's optional typing quite a bit, and my general approach is to add types if the function is intended to be reused or if it took more than three seconds to figure out what it does. We also use Typescript, and typing isn't necessary there either.

If your type system is too strict, it can be really annoying to work with and make simple things take longer. If it's too loose, you'll introduce stupid bugs.

load more comments (1 replies)
load more comments (1 replies)
load more comments (2 replies)
[-] NiftyBeaks@vlemmy.net 5 points 1 year ago

These two arguments contradict each other and together are an argument for static typing, not against. Which just shows how weak these arguments are.

The way I read it, he wasn't suggesting that was a good argument at all. He was just explaining what he believes dynamic type enthusiasts say.

This bit I am not convinced by. Inferring the API of a function from its body makes it harder to see breaking changes when you refactor the body. It can be useful for internal private helpers, but IMO public APIs should be explicit about their signature.

Well, in F# at least, this inference is the default. However, anybody can still fully type out the function signature. I think I get what you are saying, but in the case of a public API or interfaces the programmer can simply just add the type specifications.

I would go one step further here. It should support OOP and procedural paradigms as well.

Yea I somewhat agree with this. Though I mostly abhor OOP, it taken in small doses can be good. And procedural programming is always invaluable of course.

[-] nous@programming.dev 4 points 1 year ago

The way I read it, he wasn’t suggesting that was a good argument at all. He was just explaining what he believes dynamic type enthusiasts say.

Oh I read it the same way. I was just pointing out how much those two arguments contradict each other and that alone is almost enough of an argument without the extra ones the author gave. Though at the same time they are a bit of a straw man.

Well, in F# at least, this inference is the default. However, anybody can still fully type out the function signature. I think I get what you are saying, but in the case of a public API or interfaces the programmer can simply just add the type specifications.

But the problem with this being the default is most people wont go through the extra steps involved when they dont need to - which means you cannot really benefit from it most of the time. And the author implies that inferred types from bodies are always (or almost) the better option - which I disagree with.

Though I mostly abhor OOP, it taken in small doses can be good

Do you though? Or do you abhor inheritance. There are a lot of good ideas from OOP style code if you ignore inheritance (which was not originally part of the definition of OOP, in fact the original definition was very similar to some traits of function styles). It was only in later years and more modern times that OOP and inheritance was intertwined and IMO as a style it still has a lot to offer if you drop that one anti-feature.

The main argument against strictly typed languages imo isn't that types are time-consuming to write, it's that they forbid some otherwise valid programs. When writing down your types you are forced to write down some of the assumptions you make about your data (which is usually a good thing) but all assumptions aren't necessarily possible or ergonomic to express in your given programming languages type system.

Overall I have a strong preference for statically typed languages as they (usually) make code more readable and help prevent prevent bugs, but it's important to not strawman fans of dynamic types either!

[-] JackbyDev@programming.dev 3 points 1 year ago

Can you give any examples of such "otherwise valid programs"? Because a lot of times static typing also has ways to do everything dynamic typing can but it is just more difficult or (obviously) won't have the benefits of static typing.

load more comments (1 replies)
[-] eric@lemmy.ca 13 points 1 year ago

I've been liking Go. Reminds me of Python without the risk of filling my Linux install with dependencies.

[-] heeplr@feddit.de 2 points 1 year ago

So if there's a non-breaking security update of a dependency, all go apps depending on it need to be recompiled and relinked?

There's no way to link dynamically?

load more comments (1 replies)
[-] JackbyDev@programming.dev 13 points 1 year ago

With regards to immutability and pure functions, I don't really care where the language falls on the scale the author defined so long as there is a way to easily express deeply immutable objects and pure functions. There are a ton of benefits of those two things and a lot of optimizations and assumptions that can be made with them. So I don't really care if everything is immutable by default but just being able to tell the compiler/runtime "Hey listen, this thing won't change ever, got it? So go crazy with passing it to threads and stuff" or "This function will 100% definitely return the same value if given the same input so if it takes a long time you can cache the result if you're able to." both seem very appealing.

load more comments (1 replies)
[-] scottyjoe9@sh.itjust.works 10 points 1 year ago

I'm surprised that he didn't mention Rust when talking about type inference. The way it does it is excellent.

[-] cgtjsiwy@programming.dev 5 points 1 year ago

The author wanted "a more powerful type of inference that can actually infer the whole type of a function by analyzing the body of the function", which Rust doesn't have by design.

[-] philm@programming.dev 3 points 1 year ago

Which I personally think is a good decision, although I like the clean looking syntax of Haskell, it's often not obvious what the function takes (which is why most are type annotating their function)

But Rusts type annotations have non the less its limitations, when excessively using traitbounds (but I hope that will be soon better with impl everywhere (see e.g. https://smallcultfollowing.com/babysteps/blog/2022/09/22/rust-2024-the-year-of-everywhere/))

[-] naonintendois@programming.dev 2 points 1 year ago

I really prefer rust's approach. The function signature is the contract. It makes it much easier to debug compared to overly generic pure functional code or c++ templates where everything is auto and perfect forwarded.

The only time in rust where this isn't true is with async functions. That's because the compiler adds a ton of sugar to make it easier to write.

[-] hairyballs@programming.dev 4 points 1 year ago

Uh, not really? It's quite average compared to a complete inference like in Haskell and the likes.

[-] Valmond@lemmy.ml 8 points 1 year ago* (last edited 1 year ago)

Python is basically (IMO) C/C++ made easy.

Billions of libraries, works on even obscure hardware, simple syntax, no compiling(it's behinde the scene and just like always works) or linking etc. etc. etc.

Edit: this implies that C/C++ is the best language ever of course. Let the flame wars begin!

[-] Psilves1@programming.dev 16 points 1 year ago

I very much disagree. In Python almost everything is abstracted away from you and it's dynamically and weakly typed. It's also interpreted.

Compare that to C which is literally one step above assembly, strongly and statically typed, as well as compiled.

They've got completely different use cases and have almost no overlap imo.

[-] philm@programming.dev 5 points 1 year ago

And yet I wouldn't touch C nowadays if I can avoid it anyhow. Zig (simple low level) and Rust (where e.g. C++ would be used, and for large higher level projects, as it really composes nicely) are IMHO the way modern systems programming is done

[-] Psilves1@programming.dev 2 points 1 year ago

That's fine, but there are still plenty of use cases where you'd have to use C instead of anything else. I agree though, Rust is a better language than the monstrosity that is C++.

Starting a new personal project is different from what the industry requires. If you're working on integrated systems, guess which language you'll likely have to work with?

It's kind of like Typescript vs Javascript. There's zero reason to start a new project with Javascript, but there's still plenty of projects out there that use it.

[-] philm@programming.dev 3 points 1 year ago

Well depending on the "depth" of the stack Rust is probably the first choice by now for new projects in "the" industry (speaking of experience, a lot of companies are evaluating this choice now).

Have you tried Zig instead for low level stuff? It's a little bit simpler AFAIK and probably a good choice when the project doesn't get too big (in which case I would prefer Rust because of its safety guarantees). FFI is always an option...

With JSdoc and IDE support I can still understand why one would choose Javascript instead of Typecsript (having worked with both more extensively) and with e.g. https://github.com/tc39/proposal-type-annotations the boundaries will slowly fade. (mainly to avoid a massive stack of bundling and tooling software)

But I would absolutely avoid either honestly if possible Javascript (or the "static" typing Typescript is adding on top) is still not really comparable to a real strict statically typed language (apart from all the weirdness that consists in either). The way I want to program in it (functional, composable, avoiding this) is unfortunately relatively inefficient... I still don't get why it was "chosen" as the web language...

load more comments (3 replies)
[-] theherk@lemmy.world 3 points 1 year ago

Agree except Python is strongly typed.

[-] TerrorBite@meow.social 2 points 1 year ago

In what way? Python has type hinting, but it's purely for linting and is not enforced at runtime. Python has always had dynamic duck typing.

@theherk @programming

Hi there! Looks like you linked to a Lemmy community using an URL instead of its name, which doesn't work well for people on different instances. Try fixing it like this: !programming@lemmy.world/u/theherk) [@programming](https://programming.dev

[-] theherk@lemmy.world 5 points 1 year ago* (last edited 1 year ago)
load more comments (2 replies)
[-] philm@programming.dev 9 points 1 year ago

Wow I pretty much disagree with everything you said haha. E.g. packaging/venv in python is absolute hell compared to something like cargo/crates in Rust. Try to manage a large project in python and you'll likely revise your answer (if you actually know all the nice alternatives out there...)

In my experience managing a large project comes down to having a consistent process/standards and enough experienced engineers in that language. Remove that and every single language leads to abominations.

load more comments (1 replies)
load more comments (2 replies)

Interpreted language != Compiled language

load more comments (1 replies)
[-] Reptorian@programming.dev 3 points 1 year ago

Cython is a better equilavent as it does compile to C while enabling Python syntax. No one is arguing C or C++ is the best language. I'd even argue a perfect language does not exist. Simple syntax could be argued on a line to line basis, but forced indents is uncomfortable for some, and Julia could be argued to be better in that area. I'm one to hope Julia can take off.

load more comments (2 replies)
[-] Reptorian@programming.dev 8 points 1 year ago* (last edited 1 year ago)

In my opinion, it depends on your goals and scope. If memory manipulation (Probably not the correct words), and/or every bit of performance matters, or it has a large scope, then one would pick Rust/C-lang. If development time and scope is small, something like Python is better.

Source: I used C++, C#, Python, and I use G'MIC (language very much geared for raster graphics processing).

[-] pimterry@lemmy.world 7 points 1 year ago

TypeScript has become my go-to general-purpose option. Between Node.js & the web you can build anything (and share code between all these different domains), the JS ecosystem is huge so there's existing libraries & examples for everything, it gives you a good balance between productivity & performance (much faster to run than Python, much faster to write than Rust), and proper typing solves the rough edges of JavaScript without being so strict that you have to fight it.

I work with Kotlin, Rust, and Bash for various other specific things (e.g. Android apps, very low-level/high-performance code, and widely-compatible scripting) but 9 times out of 10 I'd reach for TypeScript if there isn't a special reason.

[-] natecox@programming.dev 7 points 1 year ago

Rust is my goto language today. It dips its toes into a bit of everything I like doing (webdev, cli apps, etc) and I feel comfortable with it. I haven’t found a project where Rust would hold me back yet, but I’m assuming I will eventually.

load more comments (3 replies)
[-] Code@programming.dev 7 points 1 year ago
[-] TheWozardOfIz@sh.itjust.works 4 points 1 year ago

Started Kotlin at my current job, coming from .NET. I'm impressed by Kotlin!

[-] Code@programming.dev 3 points 1 year ago

It really is an awesome language! I actually dont use it at work, but I've been learning it.

  • May I ask how your company uses it at work (not saying give exact company details, but a high level)?
  • Do you use it for web apps or Android?
  • Are any of your Devs migrating to it from Java?
  • Why are you moving to it from .NET?
load more comments (1 replies)
load more comments (1 replies)
[-] KelvinDegrees@lemmy.world 7 points 1 year ago

I've become a big proponent of static typing and the functional programming paradigm, both of which solve the problem of figuring out what you're looking at.

With OOP and side effects you can receive a variable but still not know what it really is, is it modified somewhere before or after that you missed? Is it passed deep into nested functions that modify it? Who knows! With pure functions that goes away completely, you can easily inspect what goes into it.

Static typing also solves, among many other problems, this same issue. I've written a good deal of python, and anytime I go from rust, my current love affair, back to python I end up needing to take a break and go to my dog for emotional support. I've tried using mypy for static type analysis, I still use it, but it's very far from perfect; not least because many of the scientific libraries I use don't implement static type hints and are in fact written in such a way that implementing them would be difficult or nonsensical in some instances. It's a complete nightmare. The only solution would be every one of these libraries rewriting themselves, so not likely.

load more comments (1 replies)
[-] dinodroid@programming.dev 7 points 1 year ago

The one you can use anywhere without much hassle and which you are most familar with.

For me it is PHP.

[-] BohunkG4mer@sh.itjust.works 6 points 1 year ago

I second this as it's pretty easy to learn and the latest additions in PHP 8 have made it even better to use imo

[-] colonial@lemmy.world 6 points 1 year ago* (last edited 1 year ago)

I want to say Rust, but for some stuff it's probably very overkill. I love it, but there's a reason we don't use CPP for everything. (WASM may change things here but IDK)

Swift would be an excellent candidate for the title of "simpler Rust," but unfortunately it's doomed to rot in Apple's walled garden for all eternity.

Honestly, I would say TS (which I hate, but it's indispensable for many things) or any JVM/NET language (Kotlin, C#, both are good)

load more comments (1 replies)
[-] MrJay@programming.dev 5 points 1 year ago* (last edited 1 year ago)

my opinion is a good language needs these qualities. Portable, Safe, Fast, Easy.

which seems to be similar to the author of the article. the language I have found to match the criteria the most is the D programming Language, its so mediocre in every area.

3 separate compilers, gcc llvm and mars backends. can be as safe as you want it to be, with constructs for purity, GC, and contracts built in. can be as fast as you want it to be it is a systems language and gives you all the necessary tools to go down to C level or below with a good in line assembly, but generally the idiomatic code is fast enough you dont need to go to the C level.

it is also very easy, you have a lot of C libraries and D libraries you can use and with a built in C compiler (currently beta) you can import C libraries easier, it also has a similar syntax to C so its very easy to rewrite C code in D, it has an optional GC so if you are going for max performance you can beta test algorithms quickly using the GC and when you are ready for max performance you can do it all manually, or you can use the feature to test what is using the GC so you can avoid the GC in loops, I did this in a game recently, I used the GC to setup all memory at the beginning and turned off the GC so I would never use it in a loop,

another nice feature is functional features that make the language cleaner to write. I dont think this approach of being perfectly mediocre is necessarily the best but at least on paper its very good, and in practice there have been companies (specifically Weka Digital) that swear by the approach, they can use one language for both testing out ideas and the final product. but again in a lot of cases you dont want a language that is good at everything you want one that is good for your use case.

also the article was very interesting, language design fascinates me and the article was a good read really enjoyed it. currently planning on learning Haskell and Zig soon should be fun to compare these once I am comfortable with them.

[-] PinkOwls@feddit.de 3 points 1 year ago

I so wish that D would have taken off :/

I used it at the time of the library split (there was a split in the community regarding the standard library, where Tango was the alternative). The compile time features of D were fantastic and they are still unmatched; as an example: For OpenGL (back then OpenGL 2.x) I could define the vertex attributes and had them checked at compile time when I started to fill the data with glMap! D templates and compile time code generation are on a whole new level, although it made tooling more difficult. If you know constexpr in C++, then this is nothing compared to what D has to offer.

load more comments (1 replies)
[-] flamboyantkoala@programming.dev 4 points 1 year ago

Typescript. Runs everywhere. Very active community. It’s the modern day Java.

[-] philm@programming.dev 5 points 1 year ago

I don't know I really hate when jumping to definitions in libraries, I often just land in the "typings" file. I also think that the type-system is often incoherent, has some weird side-effects and often leads to overengineering your typings... I just generally avoid Javascript based languages (which unfortunately is not really possible in frontend...)

load more comments (5 replies)
[-] verstra@programming.dev 4 points 1 year ago

I agree on basically all points. Great article, nicely explained.

[-] mythic_tartan@sh.itjust.works 3 points 1 year ago

I am enjoying Swift.

load more comments
view more: next ›
this post was submitted on 06 Jul 2023
77 points (100.0% liked)

Programming

17022 readers
217 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



founded 1 year ago
MODERATORS