/dpt/ - Daily Programming Thread

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

Other urls found in this thread:

infoworld.com/article/3217347/java/oracle-doesnt-want-java-ee-any-more.html
youtube.com/watch?v=sYd_-pAfbBw
twitter.com/NSFWRedditGif

rePost from web development thread.
>>In JSP and Servlet Class.
>> Don't know shit on how to connect and pass things between JSPs and Servlets.
>>Homework gets harder were basic examples are no longer viable.
>>Teacher offers to help via Email but takes multiple Days to reply.
>>to embarrassed to ask another student.
>>finally ask for help from another student via email. It helps. but then next step i get stuck again.

Using a dat file to add/edit/delete objects akin to a database.

Currently trying to autofill edit form with a single object's attributes depending on that object's code attribute.

Next i have to replace that object with whatever is entered into the form. After validation. which i wrote the validation tests but not the write to dat file if successful.

anime is sinful

up the irons

I'm working on Stardew Valley mods.

Literally anyone with a laptop can learn programming.
Anyone going to a coding boot camp can learn your whole development stack in several months.
They're teaching coding in schools now, it'll be part of the high school curriculum soon enough.

Why should we offer you 80k starting when literally any kid off the street will do it for less than that?

>servlets
how does it feel that you are working too hard to study a framework that is mostly dead anyway?

infoworld.com/article/3217347/java/oracle-doesnt-want-java-ee-any-more.html

>posting a pic COMPLETELY unrelated to programming and Sup Forums

anime weebsite

What are you talking about? Mental illness is very much Sup Forums reletaed.

Although gitgud.io allows anything legal, I don't want to attract unnecessary political criticism.
Standalone blog looks to be the best for NSFW projects.

gitgud still has that goobergate girl on the front page, i don't want to be associated with them or be accused of being an MRA or a trump supporter because that's effectively worse than being blacklisted these days.

>i don't want to be associated with them or be accused of being an MRA or a trump supporter because that's effectively worse than being blacklisted these days.

But you are a Trump supporter.

back to /o/ turd

not an argument, cunt.

Why are people so greedy?
I'd do it for 40k if it means getting my foot in the door.
Should I just write it on my resume?

You shouldn't. I am outta here.
*drops whiteboard*

Baka, it's a complaint about anime picture being unrelated, not about anime picture itself.
For /dpt/ OP you are encouraged to post pics with:
a) anime girls with computer book covers
b) anime girls with computers
c) anime girls from series related to Sup Forums
But not:
a) book covers without anime girls
b) anime girls without book covers or other /dpt/ related stuff
c) 3DPD in any form

>"Hi, my name is user and I am NOT afraid to be a corporate bottom bitch slave boy."

it beats my shitty warehouse job

What is the reason that the types can't be inferred here, by the way? Is it the ambiguous conversion sequence? (lambda -> std::function, lambda -> function pointer -> std::function)
:thinking:

Considering the massive amount of difference between earlier C++ and C++11,
why they didn't just make a new name for the language? Like C-2.0 or something.

How would I remove a student from the structured list of students, and then shift the rest over to fill in the vacated space, while freeing the allocated memory?
Pic related is what ive been trying with but to no avail

they should delete c++ and name it something totally different so it stops staining C. Something like sepples or ooples shit for dumbfucks

Same reason that C called itself C++.

...

They wanted to piggyback off C's success since the very beginning.

having a programming language called ooples is pretty awesome

How about simply adding better metaprogramming to C
You can already use macros for "templates", what could go wrong?

Can I see some of these macro templates?

Try using realloc rather than free. iirc free only can deallocate the entire allocated chunk, which will be the whole array in this case.

This is really tempting, but typical C code lets you feed expressions as function arguments.
If you use macros as fake functions, you'll run the mistake of putting expressions or other macros as arguments for more functions and you'll blow out your instruction cache and slow down compilation significantly because most compilers aren't good at identifying identical expressions especially when they're repeated several thousand times.

Bonus points for not using std::endl

Are you sure? Looks to me like it only deallocates the student

linked list

What implications do inline, static inline and extern inline in C?

From the C spec, chapter 7.20.3.2:

The free function causes the space pointed to by ptr to be deallocated, that is, made
available for further allocation. If ptr is a null pointer, no action occurs. Otherwise, if
the argument does not match a pointer earlier returned by the calloc, malloc, or
252) Note that this need not be the same as the representation of floating-point zero or a null pointer

realloc function, or if the space has been deallocated by a call to free or realloc,
the behavior is undefined.

There's room for making better C, too bad everybody who tries it always goes to make non standard ABI's, retared OOP and some fucked way to avoid pointer.

Better C should have just
better macro system, at least recursive macros
Bigger standard library, optional sockets, data structures and directory handling. Posix is not enough because not every system is posix compliant.
Smarter compiler, stuff like you don't have provide the function prototype before calling it if it exists in the.
If you want to go crazy, type inference and some kind of overload block like
overload fn {
int(int x) { return x + 3; } /* function name will be int_fn_int */
void(int *x) { ... } /* function name will be void_fn_intp
}
void test() {
x = fn(3); /* can determine correct function by usage */
y = int_fn_int(3); /* same as above */
printf("%d\n", x); / * prints 6 */
}

He's calling free on list[i] i.e a student*

>If you want to go crazy, type inference and some kind of overload block like
You could probably do this yourself with C11 _Generic macros.

Right, but he's probably malloc'd a single block for the whole array, in which case the list[i] will not be a pointer recognised by free (only the base pointer of the array would be free()-able, I think.

but if you use macro to wrap _Generic to provide such functionality you can only use it from C, no actual function is created. This would let you export function to be called from the library with C compatible ABI but still make it little nicer from C programmers perspective.

It'd be bad style if he did. Might as well just use a student *list at that point.

Your library would just have that macro in its header. I don't see what's special here.

>Your library would just have that macro in its header. I don't see what's special here.
Dynamically loading library and calling function there would not be possible.
Also function definitions don't belong to headers but in compilation units.

My buddy suddenly quit his job as a software engineer at a decent place. Now he works in retail for basically nothing compared to his previous salary. Never seen him so happy and calm desu. :thinking:

I'll participate in an android programming contest in a few months
what am I in for?

web apps

What is man supposed to use when here's just no good statically typed and compiled language?
>sml
no good implementaion
>ocaml
sml with shitty syntax, also does not support native threads
>lisp
too verbose, also not even statically typed
>c
decent but manual memory management is annoying in prototyping phase
>sepples
cluster fuck that no sane person would touch
>d
can't decide if it wants to have gc or no
>rust
better stay away from it because it attract lot of crazy hipsters, also uglier than sepples
> any jvm/clr lang
requires huge vm
>go
Rob Pike is faggot, also no macros
>haskell
generates garbage 1GB/s
>chapel
cannot use libraries that was compiled with it...
>ats
Jesus Christ
fun{
a:t@ype
} list_length
{n:nat} ..

If in regular expression i have this [a-z0-9] which matches all letters and numbers how do i REVERSE it, so it matches everything except letters and number specified there?

#define TEMPLATE_VECTOR(data_type, name) \
struct name##vector { \
data_type *data; \ // for nicer indexing
size_t size; \
size_t capacity; \
};

TEMPLATE_VECTOR(void, _);

bool _vector_append(struct _vector *self, void *elem, size_t elem_size)
{
size_t new_size = (self->size + 1) * elem_size;
void *ptr = realloc(self->data, new_size);

if (ptr == NULL)
return false;

self->data = ptr;
self->size = new_size;
memcpy(((unsigned char) self->data) + self->size * elem_size, elem); // may get optimized into a mov if we're lucky
return true;
}

#define vector_append(vector_ptr, elem_ptr) \
_vector_append(vector_ptr, elem_ptr, sizeof *elem_ptr);

something like this
might not be portable to all architectures though

hardware-level force quit
you tap the button and it sends a ret instruction directly to the processor at the electrical level, bypassing and overriding any kind of software whatsoever
good idea y/n

I'll have to have a play around with this sort of thing.

I completely fucked up the sizes, but you get the idea

worst possible idea /10
>hardware-level force quit
more like hardware-level force panic

>function overloading
No, C needs to go back to its roots as a portable assembler.

std::vector vec;
Sepples wins again

the fucking memcpy wouldn't ever be optimized away into movs either, though it can be fixed if you move the entire thing into the macro declaration and generate separate functions for different kinds of vectors with it
fuck i'm retarded

[^a-z0-9]

good luck making sense of any of the standard library

Static typing is a meme

C doesn't really need type inference though.

It doesn't have generics or algebraic data types, so types don't get big enough to warrant excluding them for brevity.

Granted if it did have type inference then you could combine that with overloading to IMPLEMENT generics, but why would you need generics? After all, C has no operator overloading. Your generic code would inevitably treat all values of any type EXACTLY the same, down to the byte level, so you might as well just use void *.

Then again, you're suggesting there should be function overloading, and if there were function overloading, then generics could be useful.

So I see how it is. You add overloading because it's useful, you add type inference despite it not having any immediately apparent use because it opens the path to generics, and then you combine them to add generics, which also do not have any immediately apparent use, EXCEPT for the fact that you also already added overloading, which DOES give generics a use, which retroactively gives type inference a use.

Clever.

So what stops you from doing this user?

I want some recursive macros with pattern matching.

If using auto everywhere a sign of laziness?

not really

having to write my own preprocessor which would make the code really unportable.

nah, unless the RHS doesn't give a clear idea of the type

It's a sign that your type system is so disgusting, you need to hide it.

>Static typing is a meme
Typing is a meme. There are only bytes and words. Brainlets just can't deal with Forth.

>not using B

Really bad idea desu. Due to the complexities of resource management performed by the kernel, you'd have to have pretty precise timing to get it to work as intended, otherwise it would either:
>merely cause a small and recoverable malfunction in the program you're trying to force quit
>cause small and recoverable malfunctions in unrelated programs that were working fine
>cause irrecoverable malfunctions in innocent programs and make them crash
>suddenly wipe out half or more of your open programs because you interrupted the kernel while it was in the middle of iterating through them for some purpose or another
>bring down the fucking kernel itself

Static typing without type inference is a meme.

>comparing B to Forth
Are you retarded? B is a toy in comparison.

this

Static typing with type inference is a meme. Real type systems are dependently typed, so type inference for them is undecidable.

Should I typedef structs?

On the contrary, heavy use of generics is a lot less disgusting than encapsulating the complexities of your type system in a class. OOP is utter shit, any good programming language should provide complete enough algebraic typing facilities that any type you need can be expressed as some combination or another of existing types, if you have to actually write unique and idiosyncratic interfaces for your types in the form of "methods" and "access modifiers" that's a clear sign your language lacks these basic and vital design tools.

Correction: static typing with type inference without dependent typing is a meme.
Real type systems don't give a shit what's "undecidable," they make a correct and infallible decision even when one cannot logically exist because they are fucking better than logic.

I do. The only argument people have against is that the struct tells people more about the type. I think it doesn't matter. You have to read the document or know about the types you are using, otherwise you should not use the type.
If there exists type which is user defined you should not assume you can use it like integer unless specified so. You should not try to acess type fields unless the documentation tells you that you should access them.
But whatever you do, don't typedef your struct to something like
typedef struct t {

} t_t;

_t is reserved for POSIX and only people who do thi are people who copy stuff like monkeys.

>my typing system is better than logic
idrislets get out

My logic is better than type systems. If I deem a program correct, it is correct regardless of what your inexpressive memelang type checkers think.

If you use it for basic types like auto i = 34; then yes.

If you use it for return values of functions then no.

Just use a computer without a scheduler baka. You'd have to use a jmp instead of a ret. Well at that point you might as well just push the fucking reset button.

Why would it make the code unportable? Just write the preprocessor as a script that outputs a standard C file.

>If there exists type which is user defined you should not assume you can use it like integer unless specified so. You should not try to acess type fields unless the documentation tells you that you should access them.
In that case, should I use struct for simple tuple-like datatypes, and typedef for more opaque types that have strings attached like this?

This is trippy as fuck: youtube.com/watch?v=sYd_-pAfbBw

how to write a compiler statically typed language with type inference and dependent typing:
>write an interpreter into the compiler
>run the program in the interpreter
>if it terminates, the compiled executable is an algebraic simplification of the list of instructions it executed
>otherwise, the compiled executable will eventually be just that, the only difference is "eventually" is "never"
>u mad compsci profs
>u jelly hasklets

>Why would it make the code unportable?
Because you couldn't just call
gcc my.c -o my.o
because the file would not be standard c.

instead of calling your files .c you could call them .mypp or whatever and have your custom preprocessor convert .mypp files into .c files

I'm not going to implement my own langauge. There's already too many of those.

But *_t looks nice.

This would only work for programs with no I/O, no syscalls, and no parameters.
i.e. rookie-tier class assignments

Also yes.
I mad.

RESERVED FOR POSIX

Any nontrivial project can't be compiled with
gcc my.c -o my.o

I don't see the problem at all.

The odds POSIX will use the same names are low.

No reason you'd have to actually release or advertise it if you didn't want to.

Plenty of people write their own unimpressive lightweight mini-languages like this that pre-preprocess their code so they can work at a higher level. They don't publish them, they just use them privately for development purposes.

It's really no different from writing a makefile

that's like saying that raping child is okay because changes of getting caught are low.

>Any nontrivial project can't be compiled with
>gcc my.c -o my.o
>Any nontrivial project
>Any
oh
oh friend
if you honestly believe this i am very happy for you that you haven't seen the shit i've seen

No it isn't because raping a child is wrong even ignoring the fact that getting caught would be bad
Getting caught not complying with POSIX would be bad because your program would fuck up
However, it's still not wrong

fuck make
I'm more of a "runtime configuration over compile time configuration" type of guy. When programming with C your program is likely going to use less memory and perform better than alternatives. Trying to micro-optimize seems pointless.

In Rust any project, trivial or not, can be compiled with cargo build --release :^)