/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Old thread:

Other urls found in this thread:

open-std.org/jtc1/sc22/wg14/www/docs/n2086.htm
bell-labs.com/usr/dmr/www/chist.html
docs.oracle.com/javase/tutorial/essential/exceptions/advantages.html
stackoverflow.com/questions/196522/in-c-what-are-the-benefits-of-using-exceptions-and-try-catch-instead-of-just
twitter.com/SFWRedditGifs

First for C is a miracle of this universe.

To the guy doing the Scala assignment in the other thread, you're not alone and I've got no chance.

If your language isn't functional, it's dysfunctional

If there is error in floating point representation, how is the computer supposed to produce accurate results?

>No Generics
Straight into the

If you need more accuracy in your results than floating point can provide, don't use floating point. But it's accurate enough most of the time.

>He doesn't know about _Generic

You can make your own language with generics which is compiled into C :^)

void * is good enough.

Ruby supports Functional.

kek
>This hurts a C tard
While big bois have Templates, Compile time code generations, Metaprogramming etc.
C has reached a point that it's just a bad joke these days

I heard C is slowly catching up, their latest version has finally introduced half assed generics in form of _Generics.

But who the fuck would C anyway, apart from kernel developers. It's trash for everything else

>who the fuck would C anyway
NEET Sup Forums babbies that like to role play as kernel devs

there is literally nothing wrong with Go

>templates
They're so weak (and get convoluted at any moderately complex task) you should just use someone's or write your own metaprogramming library.

Once you've done that I swear you won't go back. Even if you're a sepples fag. Most of the ideas introduced into C++ are just crippled. But to me templates are probably the most glaring example.

or people who are like interested in coding, comp sci, hacking and other cool subjects.
C is the DNA of most of the more interesting systems that true gentleman are involved in.

Don't feed the troll.

I'll admit some of the C++ templates ideas are broken
That doesn't make me interested in timesink garbo like C in anyway. C lacks waay too many things
>interested in coding, comp sci, hacking
Don't hax me with those 1337 c0ding skillz br0

>or people who are like interested in coding
How does "Coding" relate to C only?

>C lacks waay too many things
C's lack of features is a feature in itself.

Oh right, productivity is a feature of C

You sound like one of those pretentious BSD fags
>U don't need it cuz we don't

Hi Sup Forums I'm very new into coding i'm trying to chop this string into a 4 char, i hope you can help me.

String test = "abcdefghijklmnop";

System.out.println("abcd");
System.out.println("efgh");
System.out.println("ijkl");
System.out.println("mnop");

The miracle is slowly loosing popularity

print string[1..5]
print string[5...9]
..

You clearly don't understand the design philosophy behind C.

What is the design philosophy behind C again?

>C lacks too many things
In time you will realise the issues of having unnecessary or counterproductive features. maybe you already do.

The features C lack for the kind of programming you should be doing in C++ and C are very few.

The features I feel C lacks are features that let you establish contracts at compile time. Things like Ds assert expressions are great. And note how that kind of feature doesn't spread insidiously throughout the code base in any way. It's a very constrained utility. If you want to get rid of it temporarily you tell the compiler. All the features I feel missing in C is stuff like that. It will probably never happen in C because it's not that kind of language.

is there any way to dynamically iterate like every nth?

The "make a program that's impressive for 1975" philosophy

open-std.org/jtc1/sc22/wg14/www/docs/n2086.htm

>The features C lack for the kind of programming you should be doing in C++ and C are very few.
So some jew in the internet is going to determine what features I need. Great

>In time you will realise the issues of having unnecessary or counterproductive features
In what way are Generivs are "unproductive"?
In what way metaprogramming is "unproductive"?
In what way exception handling is "unnecessary"?

When is tail recursion not desired?

>C is portable
Great meme, I don't even think C has a standard syntax for anonymous functions

>In what way are Generivs are "unproductive"?
C++ templates are a step backwards

>In what way metaprogramming is "unproductive"?
Metaprogramming is a language flaw

>In what way exception handling is "unnecessary"?
Exceptions shouldn't be built into a language, and shouldn't permeate all functions

>Provide only one way to do an operation.
Is that a joke?

In the general case. While an optimizing compiler doesn't particularly care whether you use tail recursion or a while/for loop, someone who has to maintain your code will.

>in what way...
Yeah those are big topics user. It's nothing I'd bother to teach you.
>Jews decide for me
The domain decides for you. If you program in a domain the programming language isn't meant for you don't have a right to complain. C++ has a lot of marketing wank that must confuse you, it's expressed as a general purpose language but it's very specific when you get down to it. The problems with the language arises when you try to understand the features in terms of the domain it's actually useful for (where the features quickly degrade into distractions) or when you use it as a general purpose language. Its a very weak and poorly designed language for that.
C disregards the latter cases and focuses on the former. It does well there.

>It's real
Kek

You got a lot of strong opinions with 0 backings

>Metaprogramming is a language flaw
As if you and your fellow C tards would know what metaprogramming is

>Exceptions shouldn't be built into a language
Where is it specified?

I find this is a good introduction to understanding where C comes from and just where it sits now:
bell-labs.com/usr/dmr/www/chist.html

>In what way are Genercs are "unproductive"?
Templates of the C++ kind lead to object code bloat and unstable ABIs. C does not have any features which lead to a surprising amount of code being generated. Everything can be implemented relatively easily with real hardware.
>In what way metaprogramming is "unproductive"?
While primitive, C has the preprocessor.
>In what way exception handling is "unnecessary"?
Exceptions are shit and lead to inefficient code.

How is C bad in that regard?

So basically C's goal was to be the better B?

Okay

I don't think you understand the alternatives

>How is C bad in that regard?
Idiot. C has more than one ways to do the simplest of things. Programmers are bound to have different approach to the same problem. I hate this buzzword

>Templates of the C++ kind lead to object code bloat and unstable ABIs
You can create your own templates if you want to. Too bad using C will not allow you this
>CPP
NOTHING like actual metaprogramming, idiot. Learn from Lisps


>Exceptions are shit
Oh I got baited into talking to a 14 y/o

You're going to have to provide concrete examples for that.
I'm not saying that there aren't a few duplicate facilities, as I can think of a couple myself (printf(...) vs fprintf(stdout, ...))(although they provide an neater API), but it's nowhere near as bad at this like some other languages.

>Exceptions are shit
XD

while
for
do while

Are there seriously people in 20-fucking-17 who defend exceptions?
They're fucking garbage invisible gotos, and all they do is make your program harder to reason about.

How are you going to determine "the one way" to solve a particular problem? Are you retarded?

>sepples programmers who still think exceptions are a good idea
That's certainly an oddity. Unless you're straight out of school or in school that is.

>They're fucking garbage invisible gotos
>invisible gotos
kek

>while
>for
I suppose for doesn't add any expressive power over a while, but it covers such a common type of thing that people want to do, its presence is justified.
>do while
Not equivalent.

Don't blame your dumb ass if you are too retarded to use exceptions properly

>I don't need to handle exceptions
Oh boy how edgy

Hundreds of ways of printing shit

>C's lack of features is a feature in itself.
Just one of the stupid things you will see in the internet

I do use them properly:
Not at all.
And I'm not hating on exceptions purely from my own experience.

You only have the *printf family and put family.
They are all different in some way.
The only actual duplicate thing there is fputc and putchar, which was just some old performance "hack" that was popular enough before C89, so it was standardised.

You don't need to handle exceptions where they don't exist. You shouldn't be throwing exceptions. Their very nature make them a poor error handling mechanism because they're about as destructive as stderror. Except stderror doesn't hurt your performance.

And hundreds of ways of reading shit

>fputc and putchar
Whoops, I mean fputc and putc.

Someone explain this to me:
$ time python3 -c 'for i in range(1, 1000001): print(1)' >/dev/null

real 0m0.760s
user 0m0.740s
sys 0m0.020s

$ time for i in {1..1000000}; do echo "1" >/dev/null; done

real 0m10.028s
user 0m7.308s
sys 0m2.668s
Bash is crippled

Just the scanf family and the get family.

>You don't need to handle exceptions where they don't exist.
User interaction
Program interfacing
Did you hit your head with something?

>exceptions don't exist
oooh

>be C++ codelet
>don't understand parametric polymorphism
>defend templates as being anything more than CPP++
>don't understand continuations
>defend all functions being part of the exception system
>can't express yourself in your pitiful language
>defend "metaprogramming" using templates

You have to program in C for 10 years at least before promoting yourself to C++, little boy

There remains close to 0 reasons to use C anymore

Just a C tard desperately defending C's lackings. this is not new

They'd even defend C if it lacked macros

>be C++ codelet
>think everyone who points out C++'s flaws must be a C zealot

Embedded systems due to legacy and speed will always use C

>Be a C toddler
>Pretend not being a C toddler if someone points out how shitty C is

>due to legacy
Yeah mostly this. Although it's changing soon

Who are you describing?

The person I replied to.

I don't use C

Not part of the arguement but why do exceptions need to exist?
Couldn't you just program in logic to handle all cases?

>Although it's changing soon
Changing to Rust? Lmao. Not even close. Maybe in a decade. There are billions invested in keep legacy code up to date that isn't disappearing. That is the same reason why banks still run on ancient software.

It's necessary for security purposes. IoT is a source of botnet and we should be careful of their exploits

throwing an exception when you're 50 functions into the stack is much easier than typing a special return case for each level

I don't want to argue with NEETs but here goes
docs.oracle.com/javase/tutorial/essential/exceptions/advantages.html

Let's assume that you need to write some code for some object, which consists of n different resources (n > 3) to be allocated in the constructor and deallocated inside the destructor. Let's even say, that some of these resources depend on each other. E.g. in order to create an memory map of some file one would first have to successfully open the file and then perform the OS function for memory mapping. Without exception handling you would not be able to use the constructor(s) to allocate these resources but you would likely use two-step-initialization. You would have to take care about order of construction and destruction yourself -- since you're not using the constructor anymore. Without exception handling you would not be able to return rich error information to the caller -- this is why in exception free software one usually needs a debugger and debug executable to identify why some complex piece of software is suddenly failing. This again assumes, that not every library is able to simply dump it's error information to stderr. stderr is in certain cases not available, which in turn makes all code which is using stderr for error reporting not useable. Using C++ Exception Handling you would simply chain the classes wrapping the matching system calls into base or member class relationships AND the compiler would take care about order of construction and destruction and to only call destructors for not failed constructors.

>It's necessary for security purposes
No. Not when it comes to C. C is used for embedded devices. The biggest security problem with embedded devices is having access to the physical device. Not software exploits.

>No. Not when it comes to C. C is used for embedded devices.
Not because of its virtues, because of legacy codebase lockdown

this is what monads are for

Suppose you have func1 calling func2 with some input.

Now, suppose func2 fails for some reason.

Your suggestion is to handle the failure within func2, and then return to func1.

How will func1 "know" what error (if any) has occurred in func2 and how to proceed from that point?

The first solution that comes to mind is an error-code that func2 will return, where typically, a zero value will represent "OK", and each of the other (non-zero) values will represent a specific error that has occurred.

The problem with this mechanism is that it limits your flexibility in adding / handling new error-codes.

With the exception mechanism, you have a generic Exception object, which can be extended to any specific type of exception. In a way, it is similar to an error-code, but it can contain more information (for example, an error-message string).

You can still argue of course, "well, what's the try/catch for then? why not simply return this object?".

Fortunately, this question has already been answered here in great detail:

stackoverflow.com/questions/196522/in-c-what-are-the-benefits-of-using-exceptions-and-try-catch-instead-of-just

In general, there are two main advantages for exceptions over error-codes, both of which are different aspects of correct coding:

With an exception, the programmer must either handle it or throw it "upwards", whereas with an error-code, the programmer can mistakenly ignore it.

With the exception mechanism you can write your code much "cleaner" and have everything "automatically handled", wheres with error-codes you are obliged to implement a "tedious" switch/case, possibly in every function "up the call-stack".

C doesn't have monads

>

>Legacy codebase lockdown
You say that like it isn't already a big issue. Already there is python 2.7 code that will never ever be migrated to python 3 due to legacy codebase. I can't imagine the undertaking going from C to another language. Unless there is a huge advantage present, embedded systems will always be in C.

...

...

>pretentious faggot

back to plebbit with you

Oh I get it

C++ is so bad, that the only way you could hold any positive opinions towards it would be if someone forced you to program in C for 10 years

Stop posting

>sepple safe space

I never understood why C appeals to teenagers. I've had this happen to me when I was young too.

is mayonnaise a programming language

East to learn