/dpt/ - Daily Programming Thread

Previous thread: What are you working on, Sup Forums?

Other urls found in this thread:

en.wikipedia.org/wiki/Universal_Plug_and_Play
wiki.gnome.org/Projects/GUPnP
twitter.com/NSFWRedditImage

What is /dpt/'s opinion on exceptions?

Do you ever use them unless the language forces you to do so?

>Problem with virtual classes is if you ever want to add a third backend or change something that affects all backends it'll be awful.
Why?

Exceptions are okay for rare, unpredictable errors.
They should not be part of the normal program flow
Like Disk I/O errors

>Do you ever use them unless the language forces you to do so?
Exceptions make perfect sense when you use them for their intended purpose: to respond to errors that can't be handled at the call site that generated them. In those cases, the only alternative to exceptions is to manually emulate them.

Exceptions have plenty of downsides, but the value of forcing errors to be handled at compile time is not to be understated.

If you use a language like Go, it allows you to ignore all possible errors without any complaints.

A good middle ground between tedious (Java) and completely unreliable (Go) is using a discriminated union/sum type like Rust's `Result`

They frequently ruin flow awareness.
They're almost never used well and if they're in a library you use their presence impacts you very directly.

If you open up a book on modern C++ and look into 'exception safety'. You'll realize halfway through the chapter after you had your third child and multiple religious pilgrimages during page turn breaks that you don't actually want to take on all this nonsense.
So you stop reading and you don't use exceptions.
Exceptions are also never optimized by the compiler. They're too hard to deal with well. It's pointless.
As this guy says .
Exceptions is for the errors you're unlikely to recover from. Allocation errors as an example. Don't think that exceptions are for when things just didn't go as expected.

Pretty much just Erlang and Common Lisp do them right.

Should I dedicate my life to Perl 6?

...

>They frequently ruin flow awareness.
The entire point is that you don't care about the "flow" when an exception occurs. Otherwise the flow is unchanged and made clearer by omitting a bunch of error-plumbing.

Where's Perl 6?

Your third backend may need some functionality that you didn't consider when writing the virtual class, so now you may have to change it which could break the others.

You may want to optimize stuff somewhere down the line and move functions or member variables around which will also affect everything.

Also if you want to test it you'll have to create dummy objects and execute functions in order instead of just testing individual functions.

The more inheritance you have the harder all this becomes.
It might not be a problem but it could.

>calculating averages based on language
>not breaking down by field
I'm sure it's the 70% of Python users who do generic code-monkeying who make all the money. No way the 30% who do scientific computing skew that average at all.

>SQL
If you code primarily in SQL, you must be a DBA, not a dev in the conventional sense.

Good point. On the other hand, though, Ruby jobs are primarily Rails (>80% for sure), so it would make sense if Python web monkey jobs paid the same.

Man I don't feel like responding to this junk again.
You just need to know a few things. If you throw an error and don't catch it you didn't handle an error.
If you allow the user to catch an exception you've thrown you haven't handled the error. This goes even if you control both the library side and the user code side. It's a horrible api.
If the error (not exception) was feasible to handle in the code your library controls and you didn't you didn't handle the error.
If you leave your program in an inconsistent/unknown state for any reason you didn't handle the error.
The one exception is a class of errors you can't handle for fundamental reasons (user didn't fulfill your contract, mostly).
This restricts exceptions to very very limited circumstances. Circumstances where they supplement other error handling. Exceptions is not the primary way of handling errors.

They don't allow you to omit the error plumbing.
If you do that you've just ignored errors effectively. Which, fine, maybe you're OK with your user being presented with a million exceptions to handle. You've just pushed that to the user. They do the plumbing again. Or just fail as you do.

Hey this is almost a response now. I still feel like I saved time because I didn't write you an entire book on why exceptions are bad. Go read any book that teaches you how to use them and you'll find them unpleasant too.

I hate graphs and charts that don't start at zero.

>programming salary
>haskell: 0
>brainfuck: 10
Starting on index 0 as a placement doesn't make sense.

Let's say some function accepts a string, but the application logic doesn't allow it to be larger than 50 characters (maybe it will be stored in a database), are you supposed to throw an exception when it does exceed the limit? If not, what are you supposed to do?

> If you throw an error and don't catch it you didn't handle an error.

I'm not aware of any language where that is allowed by the compiler. If an exception is thrown, it must be added to the function signature to signal that it can be thrown, it must be handled inside the function, or you must specifically tell the compiler to ignore it.

Either way the error will be handled, and you decide whether to handle it in-place or pass it along (the same way you might return Result or () -> Result, Err
in another language, and trust the caller to handle the error sent back).

I'm just not convinced by your reasoning.

I meant that the bars have their leftmost part cut off, so the Swift bar look twice as long as the PHP bar, instead of just 30% longer.

>I'm not aware of any language where that is allowed by the compiler.
You mean you aren't aware of any language with unchecked exceptions?

>On the other hand, though, Ruby jobs are primarily Rails (>80% for sure), so it would make sense if Python web monkey jobs paid the same.
Perhaps. I don't know anything about Ruby. The point still stands that simply knowing which language has the highest average doesn't tell you much. A breakdown by field would give you a better idea of what specialized knowledge (of which programming language is just one part) you need to make some money.

>I'm not aware of any language where that is allowed by the compiler.
C++?

Yeah, the scale on that chart is all sorts of fucked up.

Java/C @ 102k vs Python/Ruby @ 107k is a 4.6% increase, but the Python/Ruby bar is nearly 30% longer.

So the issue you have is specifically with unchecked exceptions, and not the exception pattern in general? That seems pretty easy to solve. Just don't use unchecked exceptions.

You're not talking about what I regard as normal exceptions here clearly.
We can't have a constructive conversation like this.

You can use C++ to bash every modern programming feature, since it almost always has the worst implementation of the concept.

>Just don't use unchecked exceptions.
C++ doesn't have checked exceptions.

Sounds like a C++ problem. You wouldn't call null safety a bad idea just because C#'s implementation of it only covers primitive types.

How do distributed computing frameworks like MPI handle setting up connections between hosts?
From what I read in their documentation, OpenMPI claims to open random TCP/UDP ports between hosts to facilitate communication between processes in a job.

How the fuck am I meant to implement something like that?
The cluster I have access to has no capability to reserve ports for my job, and obviously has no such ability to communicate to each host which ports have been allocated. I can allocate port 0, which will assign me a random port, but this obviously won't propagate to the other hosts.

I want to avoid some hacky solution like writing host and port names to a shared log file and then reading them back into each process.

tl;dr how do you communicate between processes on different hosts without explicitly defining which ports to communicate on

Good with algebraic effects.

Sounds a lot like UPnP.

en.wikipedia.org/wiki/Universal_Plug_and_Play

OpenMPI itself appears to use GUPnP

wiki.gnome.org/Projects/GUPnP

What languages are you familiar with? Honest question.

>all that long-winded mindless drivel
You mark functions that throw accordingly, and let the user do whatever he wants. It's that simple. One keyword destroys your entire position.

>You're not talking about what I regard as normal exceptions here clearly.
>We can't have a constructive conversation like this.
Nobody cares what you "regard as normal exceptions". The core of your argument seems to be that exceptions make errors implicit, but this is not an inherent property of exceptions, but rather of certain implementations, and no one was talking about a concrete implementation.

>you give your users a terrible interface
>it's that simple
Yes it's that simple. But you're forgetting the terrible interface part.
And this isn't long winded at all. You need to make these distinctions with exceptions for people to understand.

>you're forgetting the terrible interface part
You've offered zero arguments for how it makes the interface "terrible".

>seems to be
I was painfully explicit. Anyone who has worked with a moderately sized code base should be able to relate.
>makes errors implicit
No that's wrong. Read again moron.

Bar foo() throws Exn;

Wow, disgusting, I can't even believe someone would write code like this.

Exn foo(*Bar);

Beautiful.

kekd

>letting functions modify object
absolutely disgusting.

Your retarded drivel makes zero coherent arguments. Try reversing your lobotomy before you post, and then you can try to explain how using conditionals to test a return value is so much better than try/catch, or why you think manually and explicitly propagating errors you can't handle is so much better than adding a "throws" declaration to your function signature.

I haven't been able to find anything supporting that claim, but I've figured out something in the way of a more lightweight solution that will work for my needs

Since a shell is required to submit jobs, I can just allocate a random port on that shell, propogate it to each host at job submission time, and then use the connection to the shell to facilitate initial process discovery.

Thanks for the suggestion anyway

>UPnP
wiki
>UPnP is generally regarded as unsuitable for deployment in business settings for reasons of economy, complexity, and consistency: the multicast foundation makes it chatty, consuming too many network resources on networks with a large population of devices; the simplified access controls don't map well to complex environments;
wonder if they tweaked it to compensate for these concerns

>Exn foo(*Bar);
You mean std::result foo*(), which is even more visually appealing.

>tfw making a commit to your project after a long period of inactivity

True. I assumed this was obvious.
If your library offers facilities to handle exceptions thrown. Unless you have good reason to make this handling optional why should you not honor their request? The request being their initial call.
You're no better than error codes at that point. Except you can't have multiple errors in flight usually. I know some languages allow that.
>waaah I can't read
>it's not coherent arguments
I wasn't aiming for a coherent argument. I made that perfectly clear in my post.
I'm not that interested in educating the unwashed masses.
I'm explaining the context for the situations where exceptions are awful. Where they're ok was already covered.
>using conditionals to test a return value is better than try catch.
I could offer you that. But I could also not do that because I NEVER argued that. But you're actually so limited you don't have room for more than two error handling systems in your head.

But again. Not interested in trying to wash the fucking pig.

>I wasn't aiming for a coherent argument
I guess that settles it. Nobody cares about your retard-tier opinions.

>still not at the point of the day where you solved the days tasks and can happily commit and do something else for a break
kill me, desu.

undercommit, overdeliver!

anyone got a link to the ftp

user I don't believe you've formed a coherent argument in your life. Genuinely. If you think we ever do that here you've got no standards whatsoever.
Post wojack more often.

>I wasn't aiming for a coherent argument
>If you think we ever do that here
>I don't believe you've formed a coherent argument in your life
>I'm not projecting whatsoever
Still waiting to see what system of error handling you're shilling for, and an coherent explanation of why it's better than exceptions.

>shilling
No user you keep using exceptions. I don't shill for anything.
Not everyone needs to know everything.

>Amateur game dev
>C has no innate support for file system navigation since it's meant to run on fucking toasters and shit
>Refuse to learn how to navigate Windows's file system via system calls because Microsoft's functions are a crime against humanity
>Just drop all assets and save files in the same folder as the executable
There is no God here today. Only me.

Why are you developing a video game in C?
At least use C++.
In C++ 14 or so there's supposed to be a portable, OS-independent filesystem API for the standard library.

P.S. I hope you realize that you're blaming C for being C. It's a low level language meant to map almost 1:1 with assembly. Of course you'll have trouble if you don't use a library.

What is the best way to learn C?

Why are exceptions always so badly named?
Like, why is it called BadImageFormatException instead of just BadImageFormat?
I don't append Class to all my classes or Struct to all my structs.

It's best if I compare C to C++.
>C-logic
"if it works, then it's good"
>C++-logic
use smart pointers, RAII, copy and move semantics--you know what, just read this whole fucking book
t. Bjarne Stroustrup

POSIX, there's libraries that make it work in windows.
SDL and alternatives might provide file and directory handling.
If you are going to include some kind of config file parser library it will likely bring cross platform directory handling with itself.
You could just use some "general purpose library" like Glib, tbox, libmowgli, foundation_lib, apr, qlibc or some other.

Exceptions are almost always used the wrong way. Even when used the right way the utility is questionable.

Use a fucking sum type.

Does anyone here know a java library or something that allows users to draw a figure in an area and tells the user which geometrical figure it is?

no, that's c++17

How long should it take to compute a table of all prime numbers in the range of 0 to 2^64 - 1

OpenCV is likely to sort-of do what you want, but in reality a neural network with N outputs per learnable figure is probably your game.

Thanks

bout tree fiddy

>you keep using exceptions
I use whatever is more appropriate on a case-by-case basis. You keep writing butthurt drivel and then resorting to "lol get educated" when asked to back it up with some actual reasoning and provide a superior alternative.

tfw too dumb to do sicp exercises without google

c is easier to learn but not nearly as productive as modern c++.

>Use a fucking sum type.
Sum types are almost always used the wrong way. Even when used the right way (to communicate an error the user can actually handle at the call site), the utility is questionable.

Use a fucking exception.

Good luck getting zero overhead on the expected path with sum types.

Not that long in sagemath
[k for k in srange(1,2^64-1) if is_prime(k)]

>c is easier to learn but not nearly as productive as modern c++
It's as productive and more productive than C++ if you play it to its strengths. When it comes to the things C++ is more productive for, it's so abysmal for those use cases that being "better than C" doesns't justify its existence.

Worth it if it ain't 100x slower on the """unexpected""" path.

>use exception handling with continuations for 99.9% of cases
>use sum types for the remaining 0.1%
Damn, that was hard.

>if you know an error WILL occur, just use sum types

>Why are you developing a video game in C?
Because I like it and struggle with big, verbose languages.

>P.S. I hope you realize that you're blaming C for being C.
This is absolutely not C's fault. It's mine. We don't disagree.

I'll look into trying some of these ideas. Thanks.

Is your brain really too small to fathom the concept of the possibility of an error that only happens under EXCEPTIONAL circumstances but still should be handled gracefully? If you anticipate the error to happen often (such as with a predictably unreliable network) or if you're working on a mission critical real time system where you can't afford the potential cost even if it shouldn't normally happen then don't use exceptions. But that's pretty much it.

Never disagreed with this. The only question, then, is what you consider exceptional.

>my brain is too small to fathom the concept of responding in an adequate manner

How can you be aware of the existence of Lisp and still get metaprogramming so wrong? Did Andreas Rumpf forget to read his SICP? Nim metaprogramming makes me want to gouge my eyes out.

Giz an example m8.

*give us

yez

I'm pragmatic about it, I estimate which one will be more efficient overall and choose that. Usually it's exceptions.

I don't know what you're trying to get at here. Is it only "responding adequately" if you explicitly implement the logic for backing out of multiple stack frames using error codes (which, again, is generally less efficient)?

tfw booze mushed my brain now i can't study properly

When might a move constructor throw?

the studying mushed my brains and now I can't enjoy drinking properly

Pretty sure MPI needs information on machines connected to the network, transfers then program with scp then calls mpirun on each machine

if he's about to drop the ladder he's carrying on his head he might throw it instead

This:
type
Foo = object
x {. baz .}: int
y: int
a {. baz .}, b {. baz .}, c {. baz .}: int

Translates to this:
TypeSection
TypeDef
Ident !"Foo"
Empty
ObjectTy
Empty
Empty
RecList
IdentDefs
PragmaExpr
Ident !"x"
Pragma
Ident !"baz"
Ident !"int"
Empty
IdentDefs
Ident !"y"
Ident !"int"
Empty
IdentDefs
PragmaExpr
Ident !"a"
Pragma
Ident !"baz"
PragmaExpr
Ident !"b"
Pragma
Ident !"baz"
PragmaExpr
Ident !"c"
Pragma
Ident !"baz"
Ident !"int"
Empty

So you never know how a piece of code is represented under the hood, and it uses dozens of these specialized nodes, but what really fucking drives me up the wall is that there is no canonical form, so you have to handle loads of special cases for when it's this kind of node instead of that kind of node, or when the node is missing entirely.

When the move constructor does anything other than swapping members.

Can't think of such a scenario.

>When might a move constructor throw?
On Sundays, when there's no one around to witness it.

Please, don't.

If it makes a deep copy and fails to allocate memory.