/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Last thread:

Attached: 1526326541596.jpg (698x712, 286K)

Other urls found in this thread:

yegor256.com/2014/09/16/getters-and-setters-are-evil.html
molecular-matters.com/products_livepp.html
vxhvx.com/
twitter.com/SFWRedditGifs

(cadddr '())

fuck opengl

>Don't do X
>Why?
>It's not elegant

Attached: 1539843648078.png (204x248, 4K)

how do I remove all empty spaces from a matrix/2d list in Python? I am new to this language and is working on a project where it is very suitable in
All empty indexes are sorted at the end of the list btw and I have a variable that tells the index of the last non-empty element

You can't cudder the empty list, user. That's an error.

Are you wearing your programming socks? Have you taken your hormones today?

Not if you're a C++ommon Lisper.

unironically fucking kys

Let's not exaggerate here. Common Lisp had the good grace to die before being transformed into a cancerous monstrosity by its creators.

Common Lisp was already a hideous amalgamation of a dozen incongruent Lisp dialects.

set_dimensions(obj.get_width(), obj.get_height());

complains that
>error: cannot bind non-const lvalue reference of type ‘int&’ to an rvalue of type ‘int’
set_dimensions() is declared as
void set_dimensions(int& width, int& height);

and both obj.get_width() and obj.get_height() return int.
Sorry if this is a stupid question, but why it doesn't work?

Attached: 1550031005291.png (1279x1065, 1.33M)

(define (filter p s)
(right-reduce append-streams the-empty-stream
(map (lambda (x)
(if (p x) (singleton-stream x) the-empty stream))
s)))

obj.get_width() is an unnamed temporary variable (aka an rvalue). Ordinary references do not bind to rvalues.

Employed Haskell programmer reporting in

Attached: 1542916826836.png (439x392, 180K)

DEC VAX computers had instructions for setting and clearing bits using mask but had no instructions for bitwise operations "or" and "xor".
This is my simulation of these operations as a part of an exercise.
#include
typedef unsigned int uint;

//these two simulate setting and clearing bits on VAX
uint bitset(uint x,uint mask);
uint bitclear(uint x,uint mask);

//these two simulate emulation of "or" and "xor" on VAX
int bool_or(int x,int y);
int bool_xor(int x,int y);

int main(void)
{
//examples
int x=0x85c;
int y=0x6A;
int result=0;

result=bool_or(x,y);
printf("%#x | %#x = %#x\n",x,y,result);

result=bool_xor(x,y);
printf("%#x | %#x = %#x\n",x,y,result);

return 0;
}

uint bitset(uint x,uint mask)
{
//set bits to 1
x=x|mask;

return x;
}

uint bitclear(uint x,uint mask)
{
//clear bits to 0
x=bitset(x,mask);
x=x^mask;

return x;
}

int bool_or(int x,int y)
{
int result=bitset(x,y);

return result;
}

int bool_xor(int x,int y)
{
int result=bitclear(x,y);
result=bitset(result,bitclear(bitset(x,y),x));

return result;
}


how did I do?

Why not? And how am I supposed to do this?

You're too cranky. Maybe you should up your GnRH dosage.

made a typo
obviously "^" in the second printf

thanks fattie, I somehow managed to solve it on my own
dataset = dataset[0:index][:]

As an ADD boomer (25) who's tried to code and hasnt gotten past the first week multiple times, what are my chances of breaking in and getting skilled enough for employment?

Mutating temporaries is something you almost certainly do not want to do because it's not useful. Look at this code.
void modify(int &x)
{
++x;
}

int get_zero()
{
return 0;
}

void demo()
{
// what is this supposed to do?
modify(0);
// or this!
modify(get_zero());
}
Not to mention, it makes the compiler's job way harder (e.g. with literals for large objects stored in static memory).

As for fixing it, either don't bother with the OOP boilerplate of getters and setters or make your getters return a reference to the underlying width/height variables rather than copies of them.

Getters and setters are procedural, not OOP, user.
yegor256.com/2014/09/16/getters-and-setters-are-evil.html

Yegor's idea of OOP is just FP without any of the brainlet filter abstractions and boilerplate out the ass.

>what are my chances of breaking in and getting skilled enough for employment?
100% if you are motivated, 0% if you aren't.
Don't rush and just take your time. Try to get into the habit of programming a bit every day.

>being transphobic
You won't get far as a python dev

Ok thanks.
I've decided to just copy values i.e.
void set_dimensions(int width, int height);

It's better this way. I also may just declare width and height public, it doesn't make a difference desu in this case.

Copying in an old commit from github history because I can't into git.

not gonna lie tho, we had a tranny(not trap) in our first semester CS classes, and all he did was shitposting on reddit on how good he was in Python
naturally dropped out after the first exam

With integers, it's cheaper just to do a copy.

I've been at "work" now for 2 days and not written a single line of code. I've just been looking through the code they already have and tried understanding it, singlestepping through it with a debugger and so on. Is this normal? I feel terrible that I've been so unproductive so far, but it's just really hard to get into all these abstractions, implicit behaviour being imported and done behind your back and having to look up and memorize what all those typedefs of typedefs of some more typedefs and so on all end up being. The documentation they have seems terrible and briefly was like
>btw be careful with these functions they might deadlock lmao
without even mentioning what could go wrong or what locks are taken.

>In true object-oriented programming, objects areliving creatures, like you and me. They are living organisms, with their own behavior, properties and a life cycle.
>
>Can a living organism have a setter? Can you “set” a ball to a dog? Not really. But that is exactly what the following piece of software is doing:
>
>Dog dog = new Dog(); dog.setBall(new Ball());
>
>How does that sound?
>
>Can you get a ball from a dog? Well, you probably can, if she ate it and you’re doing surgery. In that case, yes, we can “get” a ball from a dog. This is what I’m talking about:
>
>Dog dog = new Dog(); Ball ball = dog.getBall();
>
>Or an even more ridiculous example:
>
>Dog dog = new Dog(); dog.setWeight("23kg");
>
>Can you imagine this transaction in the real world? :)

Attached: 1497370418079.jpg (171x189, 24K)

Attached: behead object oriented programmers.png (590x448, 202K)

docs is so important
im sorry op i always have this problem myself when i want to contribute to existing oss projects but i cant because its so hard to understand what was already written even though i already made some oss projects myself

starting to emulate a midway 8080 cpu, finished Chip 8 a couple months ago

No, enterprise programming is very unproductive
Code reviews, meetings, mentoring, corporate politics (birthdays every week) that kind of stuff
Everything has to be tested and discussed before implemented or you get an army of bugs, especially in a code written by ~50 people

In my free time I write a thousand lines for every ten I do at work

I've started learning C++ recently, and I gotta say, I really enjoying it so far. For user who program in C++ and are really good/experienced at, how long did it take you to get good at it?

Nobody truly "knows" C++
For instance template metaprogramming was discovered. Not added to the language. Discovered.

30 years ago

Unfortunately, that sounds pretty normal for old, largish legacy type systems.

That didn't answer my question, but alright.

For me I'd say about 3 months. Including metaprogramming tricks.

Is it valuable to learn perl

Can you give me some sources?
I want to shine at the coffee machine by parroting this story.

Did you expect that template specialization would lead to turing completeness?

You have 10 seonds to write the most pajeet code you can

Car car = new Car();

/dpt/-chan, daisuki~

>What are you working on, Jow Forums?

Exploring the deepest, darkest corners of Racket.

Attached: s.png (1534x1013, 160K)

if (thing.substring(0, 5) == "hello") {
...
} else if (thing.substring(0, 5) == "world") {
...
} else if (thing.substring(0, 3) == "hey") {
...
} else {
...
}

Hideous but powerful. Like an old scarred warrior or a human-leather bound spellbook.

It’s my favorite ugly language.

What are some good books for Linux kernel programming?

Attached: d87e2aa8af7a22a28435e05ba5c6f1f10c21b417.jpg (600x800, 73K)

There exist Lisp dialects that aren't such messes.

"Linux kernel" is redundant, user. You should just say "Linux", otherwise you're giving people the impression that "Linux" may refer to more than just a kernel. If you wanna avoid any confusion, you may say "Linux, the kernel", though.

I want to choke this "Linux kernel is redundant"-guy

I meant specifically programming linux kernel modules

BigInteger a = new BigInteger("12");
BigInteger b = new BigInteger(222222222222L);
BigInteger c = BigInteger.TEN;
BigInteger result = a.multiply(new BigInteger("20").add(b)).subtract(BigInteger.ONE).divide(c).add(b);

>programming Linux modules
FTFY

ActiveSheet.Range("A1").Copy Destination:= Worksheets("Sheet2").Cells(1,1)

But do they have true condition handling, CLOS, an stable ANSI standard, image based facilities such as redefining class fields on the fly, many mature implementations that include targeting JVM or compiling to C, performance close to C++, and reader macros? I’m sure I’m missing some things but anyway sometimes being an ancient abomination has some advantages.

Daily reminder that Ada was the best programming language ever made but the jews killed her

Nvm found it

Haskell from first principles, i assume?

size_t
STRLEN (const char *str)
{
const char *char_ptr;
const unsigned long int *longword_ptr;
unsigned long int longword, himagic, lomagic;

for (char_ptr = str; ((unsigned long int) char_ptr
& (sizeof (longword) - 1)) != 0;
++char_ptr)
if (*char_ptr == '\0')
return char_ptr - str;

longword_ptr = (unsigned long int *) char_ptr;

himagic = 0x80808080L;
lomagic = 0x01010101L;
if (sizeof (longword) > 4)
{
himagic = ((himagic

Izzat some gnushit

How do I protect my code?

hide it in your ass

write it in a useless esoteric language so that nobody will ever understand it or run it
pic unrelated

Attached: 1549310003146.png (1280x720, 891K)

Encrypt your backups

Zip with a password

Fill it so full of explicit language nobody would dare use your code.
The more incorrect, the better. Add pedo shit, ad racist shit, anything you can think of.
Just make sure you don't put it on your résumé :^)

Start every file with "Tiananmen Square 1989"

based

molecular-matters.com/products_livepp.html
Pretty cool library. I haven't read the source but how would you handle changes to struct layout during live code reloading? Seems like that requires reflection. And dll allocated memory sounds tricky to fix.

Lisp is the most powerful programming language.

I was expected to read books and study for a year before working (very knowledge-based company). There's a reason you're given like 2-weeks/a month minimum to adjust. If they expect you to work right off the bat they're a bad company.

I've been working on an Icecast client for easy internet radio streaming, with plans to add multiple channels, song directories and a voting system.

vxhvx.com/ critiques welcome

Attached: site.png (1600x816, 462K)

Common Lisp is the best, most practical Lisp dialect.
You are not forced to use its "ugly" features, but they are there if you need them.
Big languages with more functionality are better than small, crippled toy languages if your goal is actually making software.
Get fucked boomers.

>You are not forced to use its "ugly" features, but they are there if you need them.
Please name one "ugly" language where this does not apply.

Have you read your SICP today?

Attached: 1543262954743.jpg (800x534, 66K)

What is the best programming language for making/using DSLs to solve problems? For me, that’s the most enjoyable part of programming. I want the flexibility to make my own tools/sub-languages.

Lisp, unironically. Macros are a godsend.

Haskell.

DSL and lisp have always gone hand in hand. Racket specifically is a language focused on creating new languages. Any lisp can do it well though. With common lisp your DSL can compile to native code.

Racket is basically designed for this.

I really like Perl. Some of the errors/indirection you do can be near-incomprehensible, but for most small things it's very good. I've written over 1000 lines in it, a lot of which was just for breaking down a single txt based "table", which could be oriented top down, down right, had multiple states and built-in implicit rules (a state could mean two things depending on the context).

In some ways it's just a much more understandable bash replacement, and let's you do more complicated things. For real programs? I probably wouldn't use it, only for slapping infrequently-used shit together and manipulating files.

My dad told me that every programmer has a "wife" language; a language that you marry because you love it so much. For him it was PHP when he was back in college because it was easy and fast.

What's your "wife" language?

Common Lisp.

I have two girlfriends. PHP and Javascript. Hello web developers!

I don't have one cause I'm not a shit programmer I just use whatever's best for the job

Anything

If the job is personal project with no specific library requirements, the best tool is the language you like the most.

Not gonna lie, it's Ruby.
I'm a 30 year old boomer and Rails was trendy as shit when I was trying to get a job out of college. I have fond memories of it.

Clojure

not really, it still depends on the job

There are many langues that purport to be general purpose. Languages can obviously have radical differences (ex. garbage collected/not), but for a given task there are likely many languages whose domains contain that task. The idea that for any task there is one best language is stupid.
In addition, a language which is suited for a particular problem domain that you enjoy working on could be considered a “wife” language.

I have a harem

even so that's more about the language you're most familiar with
having an emotional attachment to a programming language is anti-intellectual

Just a less figurative way of saying the same thing but alright. What language are you most familiar with?

Trying to design an ipc system on windows, new to interop and I can't decide on how to model it.

I have important data being collected by one process, where only the most recent message is valid - every message that comes before the current message is invalidated on each update.

I want the most current message to be consistently available on-demand to the second process without either process blocking.

I tried using named pipes and mailslots and there doesn't seem to be a way to invalidate or flush old messages so the second process can simply access the current data.

What should I do?

#include
#include

int main (void){
bool digit_seen[10]={false};
int digit;
long n;

printf("Enter a number: ");
scanf("%ld", &n);

while(n>0){
digit=n%10;
if(digit_seen[digit])
break;
digit_seen[digit]=true;
n/=10;
}

if (n>0){
printf("Repeated digit\n");
}else{
printf("No repeated digit\n");
}

return 0;
}

how do I make it so it also prints the digits that were repeated?