/dpt/ - Daily Programming Thread

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

Other urls found in this thread:

termbin.com/sai0
twitter.com/NSFWRedditVideo

re-implementing F* in COBOL

Reminder that over- and underflows are desirable when working with unsigned integers and in fact you should do them manually to make sure their behavior is well defined.
// instead of
++i;
// do
i = (i == UINT_MAX ? 0 : i + 1);

pure unbridled unreadable unemployable autism code

It still sucks, mate. Show me how to call a virtual method on a C++ object from Python and we'll talk. Also, explain what happens when C++ throws a fucking exception into the Python code.

Just let it overflow, life is more fun that way and everyone is happy.

unbehind defavior

unsigned integer overflow is well defined behavior. signed integer overflow is UB.

Both of those are defacto standardized by Itanium but you're never gonna see an FFI support them.
Just expose free functions and it'll all be OK.

or just use a non shit compiler

Unsigned overflow is defined, monkey. Only signed overflow is undefined.

>just expose free functions

That's just the thing, you know? If you're going to restrict yourself to regular SysV ABI with extern "C", then what's the point of all the fancy C++ shit? Just wrap the entire thing behind a C header file -- the actual implementation could be written in Pascal and nobody would care.

I seen some amazing FFI shit and it's really opened my eyes regarding how shitty the C++ situation is. I've seen papers describing a Scheme .NET FFI that allows loading up CLR assemblies and calling methods on objects. I've made native libraries that link with the JVM, CLR, V8, even fucking Ruby. I've done the opposite: loaded up the entire virtual machine in my application's process and proceded to use Java/C#/JS/Ruby code from within my program. Yet people can't fucking unmangle a fucking C++ symbol.

Can someone explain to me why they clipped those 0's from the mantissa? They're on the side of the least significant bits so removing them does change the value of the binary number... or so I think?

Hi, incompetent faggot here with no coding knowledge outside of a handful of Linux commands and basic Python from the last thread who some great user helped with a gap detection python script.

If I have a structured file like this:
3=
{
name="A"
culture="B"
}
1=
{
name="A"
culture="B"
}
2=
{
name="A"
culture="B"
}
3=
{
name="A"
culture="B"
}

How do I grab the last one in the file automatically (instead of the "please type first useable number" I'm using now)?

Stop merging unfinished/wip code into the main branch!

While I don't think it's necessarily bad practice to check if an integer is about to overflow, ignoring the overflow and just resetting i back to zero is how hard to track down bugs occur, because this is literally silently ignoring an error and acting like it didn't happen.

make me bitch

I would if I could.

i'll unmake you

>grab the last one in the file
elaborate
grab with what, for what purpose?

But I have no branches other than master...

they are to the right of the decimal point user
1.100000000 is equal to 1.1
the mantissa doesn't represent an integer

with the floating point mantissa, there is an implicit "1." added onto the left end -- a mantissa of 011 actually represents a value of 1.011

I really need some neat tool to batch process string shit

writing c++ program everytime I need something like is literal insanity. python? ps? sed, awk?

So I was currently rewritting my old script to manage my todo-tasks, and broke down my thoughts to those specifications: termbin.com/sai0
Should I change something in design? Should I generalize something? Thanks in advance.

Sorry, I need to grab the last
1={}
aka the last entry's number in the file to a var.

Pre-existing code base.

Forgot to add: I am writing script in BASH, so there would be limitations in programming and level of abstraction.

length of list

Are you a C alchemist ?

>apple

>orange

Just use a TODO web app, bruh

>not writing all programs you use by yourself
What are you, botnet's slave?

why don't places like NASA use idris when it's so important for their programs to be correct?

>idris
>correct
answering your own questions there

Mind explaining?
The list itself goes from 10032 - 3024 and from 1000023 to 1000234, so just counting the length feels like a lot of effort for a semi-trivial "n = last i (where i is the number of the last entry)"

If unsigned integer overflow is well defined, while signed integer overflow is UB, then why C's implicit type is a signed integer?
Also why C++'s literal character is a signed type?

r8 my programming skills Sup Forums.
Also, guess what I'm working on

>letlet

It's code for a game. Worst code I have seen so far. Also >let >brainlet

>r8 my programming skills Sup Forums.
0/10. Reason: Not using Sup Forums certified language

>Also, guess what I'm working on

Can your lang ensure totality?

you're that guy making the shmup for ishit right?

> complaining about let
fucking varlets

yeah, it's me

It's also important for their programs to be timely.

>be me
>phone interview with company
>all went well
>they sent me a code problem to solve at home
>i have 1 week to do it
>the problem statement is
>>will a given function terminate or not?

friendly reminder to not let seedy people work on your projects
you really don't want shit to blow up in the future all because a nazi had his hands in your projects

>seedy people
?

def:

people who seed too much

what the fuck are you sayin

I never seed. ever

you seed
you bad
very bad
naughty even

good, I trust you

Yes, and? Sounds simple. Just trace its execution.

who are good youtube programmers that I can turn on in the background? I find it helps me program, even if I'm not listening.

>mods are pretty quick to ban "unrelated posts"
>don't ban trap posters
I guess programming socks are technology related.

to be fair they literally do talk about programming

I've been backgrounding Jblow's streams for a bit.

Am I a fucking moron?
file.write(str('{}= {\n\tniggers'.format(dynnumber, dynname)))
When executing the script, I get
ValueError: unexpected '{' in field name
How can I fix that?
Python btw.

It looks like you're just missing a } right before your \n

How long until apple drops Swift and develops something less retarded and bad?

Why, for the love of god, did you not indent your bracket couplets. I don't usually feel autistic in my life but this single coding practice makes me livid.

I'm an idiot, that { needs to be there because it's part of the output (not as a placeholder) and totally forgot about it..
Thanks, user.

What's a good programming project?

what are you talking about dude? It's perfectly indented.

>let
>let
>let
>boss?

For the love of god someone put this thing out of its misery.

this is a test to find out whether their applicants actually know the theory behind CS concepts or whether they're just code monkeys from a "boot camp"
from the sounds of it you've already passed

>swift: hey bro can i copy your homework?
>rust: yeah man just try not to make it look too obvious

here, have some pseud code
max = 0
for record in file: # where a record is defined by you
n = record.parse_num() # get the number you want
if n > max:
max = n
# now max is the max

sounds fun desu
mind posting a similar function here

Your program seems like it's really uncertain about where there is a boss or not

>apple
>becoming less retarded and bad
the question answers itself

There doesnt need to be a boss for there to be a boss.

what's wrong with let?

easy.
def terminates(f):
f()
return true

okay but how do you do it in a lazy-execution language like haskell

that's because the boss is too weak ;^)

i am trying to program a forth in forth in forth in forth

In C:
static char array[10];

void somefunc()
{
array = NULL;
}


What happens there? Is the memory deallocated? Is it a memory leak? Is it even valid C?

how do you do what?

looking to start learning python, what are some good books or materials you guys would recommend?

>how do you do what?
def terminates(f):

automatetheboringstuff

boss number 3? ...maybe?

yeah, each boss has its own subclass, following the same protocol for the (((AI))).

Why the fuck multithreading a function that can throw an exception in C++ is so confusing and weird
You need a function to catch the exception, raise an error flag via global variable or a pointer to a variable,
then the caller function need to parse what is wrong in the worker thread via the error variable, and re-throw another exception to higher order function

with that many bosses it's starting to look like a real tech startup!
nice!

Exception handling is just mind bogglingly horrible in C++.

kek

Post AI and be criticized.

>Is the memory deallocated?
No
>Is it a memory leak?
Yes and no. The memory pointed by array is unreachable anymore, but because your program didn't call another resource requesting function, the unreachable memory will not increasing.
A global variable will be valid for the whole program whether you use it or not anyway, So it's technically a "leak" but not a problematic one.

>Is it even valid C?
Somewhat

Statically allocated memory can't be deallocated by definition. It's part of the actual object file.

Agreed. All documentation saying that Exception is used only in special case where something is horribly wrong, but you want the program to handle it as possible,
and also exception violate lots of C++ rules because it's something special.
But lots of people, and even the STL throw exception like a tic tacs

I see. Thanks!

it's shit. Basically just controlled random decisions, not real AI at all.

I definitely can do better, but it's not necessary for my game.

Why use the switch-case statement if your only options are nil and default? Planning on adding more cases in the future?

That's cool, it's not like the user's gonna notice anyway, I made a Rock-Paper-Scissors game for my swift class and my State-Of-The-Art AI is basically producing a number between 1 and 3 at random but if the user picked the same thing twice in a row it countered the case specifically, I might make it better in the future if I can into Machine Learning, but that seems like a long shot at least this semester..

possibleDecisions: possibleDecisions

what is this trash

>Planning on adding more cases in the future?
yeah

just an argument label from the method

I get your pseudocode, but the number I want is the last entry in the file. What do you mean by max, btw? I just do last_number+1.

Here's an excerpt if it isn't clear.

1000252098=
{
name="Tokhid"
culture="afghan"
}
1000252099=
{
name="Lodi"
culture="afghan"
}
1000252100=
{
name="Nasherid"
culture="afghan"
}
1000252101=
{
name="Hotaki"
culture="afghan"
}
1000252102=
{
name="Karlani"
culture="afghan"
}

Basically, it needs to scan from the bottom (I guess?) for the last "n=".

possibleDecisions: possibleDecisions: possibleDecisions

Revolver Ocelot.