/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Old thread:

Other urls found in this thread:

github.com/Dako300/BasicTV/pull/2
open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf
en.wikibooks.org/wiki/Haskell
twitter.com/NSFWRedditVideo

>it's the same autist making these threads early because he's triggered by the regular OPs

What do I add to this OS?

make the desktop a maze, like an actual crypt

randomly generates each time it starts up
your mouse is locked in and can't cross walls

if you aren't editing your files with ed it doesn't qualify as programming.

The only one triggered here is you.

TAOCP is a meme

Hmm...interesting. I like it. I'll make it a app. So it's voluntary.

>ed
Erectile dysfunction? I don't even...

>voluntary
no

It would be just 100% tedium if the desktop was a maze.

do it

it's called cryptos

i live in seattle can i get a code monkey job with no degree

do you know Java?

Ok, I made my pull request:
github.com/Dako300/BasicTV/pull/2
It should trigger recompilation for the relevant files when a header changes.
I also made the output fancy, but you can remove that if you want.

Thanks

Tell me why I shouldn't use C

You should use C though.

Because you could use Jai instead.

Bad programming practice

actual functionality.

Memory management
No exception system
Macros

Unless you're really familiar with it or you have to use a C library without bindings, it is extremely hard to use properly.

>Memory management
???

It's hard to use properly if you're coming from a garbage collected language.

>Memory management
Every language has memory management.
>No exception system
That is a good thing. Exceptions are terrible.
Also, setjmp/longjmp exists, for all your shitty needs, but I don't recommend to people that they use it.
>Macros
Macros are a good thing. Even a shitty text replacement macro system is better than no macro system.

In k&r c, is it important to do every exercise if I already have experience from AP Comp sci and am going to school for CE In a few months? Could I just look at the solution to some exercises that I don't want to spend the time on and read documentation about it then move to the next section? I only ask because my schedule is getting pretty tight but I still want to make room for /dpt/ stuff.

a jit compiler for a language used to generate fractals / music.
ncurses based piano using said language to generate notes (uses sndio).
because poor and want to learn

>No exception system
>what is CEXCEPTION

non argument

garbage collection is shit for C

"it's hard" is not an argument

I meant that manual memory management is hard, and only useful for extreme optimization.

I suppose that exceptions can be considered to be bad, you're right. What I really meant is that without a debugger, the language does not give a description of the error that occured.

Macros, compared to templates, are incredibly unwieldy and hard to debug.

Also, a few things minor things I recommend you do with your program:
Add a .gitignore, add *.o, .depend, basictv and whatever your text editor spits out (e.g. *.swp for vim).
It's just very nice to have, so you don't accidentally commit some crap to your repo and cleans up the git status output.

You should use pkg-config instead of just specifying off of the -l commands yourself. It's a bit more portable that way.

Okay. I might start doing these since I've built up an audience

>manual memory management is hard
You should stick to webdev.

>manual memory management is hard
You didn't say "_manual_ memory management". You just said "memory management".
>is hard
No it's not. As long as you have a clear idea about pointer ownership, it's actually pretty damn easy.
>the language does not give a description of the error that occured
strerror(errno)/perror() exists. A lot of libraries also provide similar facilities.
>Macros, compared to templates
They are not the same thing. Macros (in C at least) are just a simple tool to replace one bit of text with another bit of text.

See for some more explanation of my thoughts.

The thing about C memory management is that it relies on the programmer to correctly dispose of and create values, which if done improperly will cause obscure but serious problems which are hard to debug for a less experienced programmer.

Of course, for a C expert all of these problems are far less severe, and for that person, C becomes an incredibly powerful tool.

>for a less experienced programmer
Why on earth should everything have to cater to idiots?
It's not Go we're talking about.

>Exceptions are terrible.
Epic opinion! You'd think that a C user would understand the concept of picking the right tool for the job.

GC for C might be the dumbest thing I've ever heard

>Hidden goto
Yeah, no thanks.
It's not even a niche opinion to think that exceptions are terrible, unless if you're a Java programmer or something.

just use the (ExceptT e) monad transformer

>spending extra cycles on comparing and branching for something that normally won't even happen

Exceptions aren't free, you know.

I'm sorry. I meant that `manual` memory management is `hard to learn and use if inexperienced.`

Templates and macros are very commonly used for the same purpose, and my opinion is that templates are better in that situation.

Haskell Fags will defend this.
{-# LANGUAGE DeriveDataTypeable #-}
module Smuggle where
import Control.Exception
import Data.Typeable
import System.IO.Unsafe

data Smuggle a = Smuggle !a deriving (Typeable, Show)
instance (Typeable a, Show a) => Exception (Smuggle a)

smuggle :: (Typeable a, Show a) => a -> b
smuggle x = throw (Smuggle x)

recover :: (Typeable a, Show a) => b -> a
recover x = unsafePerformIO $ do
val return x
Right _ -> undefined

idInt :: Integer -> Integer
idInt x = x

main :: IO ()
main = putStrLn (recover (idInt (smuggle "foo")))

Haskell's built in exceptions are a mistake, use monads for that instead

Unless you're terribly concerned about executable size, actually, they are. When they're not thrown, at least. This is talking about exceptions that are implemented using a map from instruction pointer addresses to exception handler subroutines, of course, not SJ/LJ exceptions.

I'm sorry if I implied that C should have GC; obviously, that would be ridiculous. I meant that other languages are more useful in many situations because they have easier to use memory management models.

manual memory is critically important for C, but maybe having scoped objects (objects in the C sense) isn't a bad idea

>having scoped objects
They're called automatic variables.
You know, the normal kind of variable.
void fn()
{
int a;
{
int b;
} // b no longer exists
} // a no longer exists

I mean with custom constructors and cleanup

That's not a scoped variable. That's RAII.
However, that feature is not in the spirit of C, and will probably never be introduced.

like C++ filestreams

{
std::fstream f (file);
// file opened
... do stuff with f ...
// file closed
}

gcc and clang have the cleanup attribute

in that respect it is like Java

C extensions are not C.
They probably only have that because those compilers also support C++, so it isn't really a big deal for them to implement it in C.

The only thing I'm missing from C ist stack-arrays of variable length. Something like this:
struct S {
bool a;
bool b;
int c;
};

int f(char *filename, int len) {
int res = 0;
struct S ary[len]; // look ma, no heap!
// load stuff from files into the structs and do some operations on the data (setting res to some value)
return res;
}

you mean in C++? because C has that

inb4 butthurt C++ (like Ruby) claim they don't want that feature.

>because C has that
Show me the code then.

>Show me the code then.

Also, here is more proof.

it's a part of c99

open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf

section 6.7.5.2

Oh. I could swear "some" C(++) compiler threw an error at me last time I tried it.

Personally, I have only ever used VLAs for extreme optimization cases when the amount of array elements is less than 256.

You were probably using a C89 compiler like an idiot.

Maybe it was Visual Studio? Hmm.

Putting too much data on the stack is dumb anyway. But it's really convenient not having to allocate memory on the heap.

It might have been Visual Studio at work.

hey, I have the same aspirations as that guy and I know some Java and I'm learning Spring. What should I do to reach to achieve employed code-monkey status?

if you know Java you've already completed your first step by becoming a code monkey

what else?

Is pic related a complete meme?

Are you good with OOP yet?

Both.

No it's pretty good.

>when the amount of array elements is less than 256
Why not simply make an array of size 256?

It's doomed. They're never going to add HKTs. They should have been designed in from the start but they weren't.

Just another wasted effort. Countless man-hours down the drain.

>HKTs
Hong Kong Telecom?

Yeah

But VLAs are more useful than just that.
It allows you to do more fancy shit with the type system and convey meaning to the compiler and programmer.
void my_fn(size_t len, int arr[static len])
{
// Do something with arr, knowing that it's non-null and at least 'len' elements
}

void my_fn2(void *base, size_t size, size_t nmemb)
{
unsigned char (*arr)[size] = base;

// Iterate over array of unknown type, but known size
for (size_t i = 0; i < nmemb; ++i) {
// ...
}
}

Would be nice, but you should consider C++ to be distinct from C, only looking very similar in syntax. It's not incredibly difficult to use a vector for the same goal, and the memory can be moved out of scope easier. Yes, its not guaranteed to be stack allocated, and yes its more verbose. But welcome to C++

Is it a good idea to learn SASS instead of CSS?

You better have a code of conduct or I'm gonna report you to github

>hacky dependent types
Nice feature

no. learn CSS then learn SASS or LESS or whatever the fuck it is that's abstracting CSS

>go to college for IT
>learning basic programming stuff
>Java, C#, some web languages
>get to final term
>think it's time for some challenging concepts or algorithms and how sorting works
>nope it's all fucking meme languages like Ruby+Rails, android dev, and python
>because apparently this is all employers want

how do I teach myself non-OO languages? I want to learn something fast

>IT

I'd like to use int ar[static 1] as a portable nonnull type but I don't think any compiler implemented proper warnings for that last I checked. Modern compilers might do that now.

>I don't think any compiler implemented proper warnings for that last I checked
I think clang does.

Just download haskell or racket and start playing with them. Since you dont care about getting a job you dont have to worry about them being meme languages or not.
Try to implement a lisp evaluator, and haskell's type inference, in either or both languages.

Implement a simple game (i.e Tetris) using C and OpenGL.

Also SDL/GLFW for timers/input handling.

>how do I teach myself ...
Pick up a book or google for some tutorials. Why do you need our advice on this?

en.wikibooks.org/wiki/Haskell

Why didn't you do a proper thread after bumplimit of the old thread?
Your efforts would be appreciated.

Trying to work with UDP sockets in C++ with a client and a server talking to each other over localhost. Right now it's just the server receiving all the packets and the client can't get anything back. I tried looking up tips on how to solve this problem and I don't know if I just need to improve my googling skills or whatever but I can't find anything to help me.

Program flow:
>server starts
>server spins up socket and binds to port
>client starts
>client spins up socket, but doesn't bind (bind would always fail since the server was already bound)
>client sends packet
>server gets packet
>server sends packet in response
>server gets the response packet

Kinda new to this socket thing, and I'd appreciate someone telling me how to fix my autism.

> the color for Java on github is brown

You need to use threads and/or non-blocking I/O.

OOP == POO

What does the NAT look like? In such a situation, both the client and the server should have their ports forwarded (unless this is all local).

>Java
>coffee
>it's coffee-colored
Yeah, dude. Yeah. It is brown.

Both are running on localhost which I believe is the root of the problem, and which I am trying to make work.