/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Old thread:

Other urls found in this thread:

hastebin.com/oxavasifay.cpp
en.wikipedia.org/wiki/COMEFROM
hastebin.com/equfaviruh.cpp
thestarman.pcministry.com/asm/mbr/STDMBR.htm
thestarman.pcministry.com/asm/mbr/MSWIN41.htm
twitter.com/SFWRedditVideos

Rust is a language with promise

can't even initialize a struct on the heap without crossing your fingers and hoping the optimizer elides the copy

I'm writing a switch function but when I the default case is used, it prints out the statement 3 times

int value(char romanChar) {
switch (romanChar)
{
case 'I':return 1;
case 'V':return 5;
case 'X':return 10;
case 'L':return 50;
case 'C':return 100;
case 'D':return 500;
case 'M':return 1000; //cout

code tags

Anons, I need help. I want to create a web page with a simple signup system.
I've already done a database and a C++ program to singup users.
I now want to do a web page but I have no idea how to connect the web page with the database
Pic related is the web page.
In other words, I just want the buttons to send the information and store it in the database, like the C++ program does

Also. How do I change the text in the buttons?

Sepples was a fucking mistake.

I know

Im working on learning clisp

and Im about to hurl my thinkpad across the room. None of my shit is working when I try to compile it from notepad

The code actually gets simpler.
Desc : Type -> Type
Desc a = a -> (b : Type ** Interpolator b)

entity : Desc a -> Type
entity d = (x : a) -> fst (d x)

interpolate : (d : Desc a) -> Interpolator (Entity d)
interpolate d t e e' x = (snd (d x)) t (e x) (e' x)

EntFields = X | Y

entDesc : Desc EntFields
entDesc X = (Float ** lerp)
entDesc Y = (Float ** lerp)

Ent : Type
Ent = entity entDesc

ent : Ent
ent X = 100
ent Y = 200

notepad isn't great for programming

int roman_to_int(string measure) {
int i, j;
int total = 0;
int max_value_so_far = 0;
j = measure.length() - 1;
for (int i = j; i >= 0; i--) {
if (value(measure[i]) >= max_value_so_far)
total = total + value(measure[i]);
else {
total = total - value(measure[i]);
}
max_value_so_far = value(measure[i]);
}
return total;
}
int main() {

string julius;
string brutus = "b";
int octavian;
cout > julius;
while (julius != "b") {
// if (julius != ){
// cout

Could someone find the bug in my code?
I'm trying to write a function in C that takes two strings s1 and s2, and removes any character in s1 that is also in s2. Here is what I have
hastebin.com/oxavasifay.cpp
The resulting string always contains a tail of the last character, whose length is the difference of the original string 1 and the edited string 1 (so it appears the function continues printing the last character until string length is reached).

Also, I tried adding extra conditions to break out of the loop , but they never seemed to fix the problem

Does anyone know of a good project management / scrum tool that is 1. free as in freedom and 2. offline with a local / easy to share database?

CODE TAGS

[ code ] without spaces [ / code ]

So if you need a new field, you just add it to EntFields and entDesc and it doesn't break anything?

You will also of course need to change the "constructors", but yes.

>You will also of course need to change the "constructors", but yes.
"Constructors" being all the bits that go "ent Property = value"?

host kanboard on your own computer with sqlite

Yes. Idris doesn't have nice pattern matching lambdas but ideally you would be able to create objects anonymously more like this,
\{X => 100, Y => 200}

In Idris it would look like:
\x => case x of
X => 100
Y => 200

Agda has this feature.

switched to notepad++

it was a fucking extra paran in one of my functions that I didn't completely delete last night. I can finally compile thank god

Tried code tags. It didn't work. Probably using them wrong. Quick rundown on codetags?

write the post without spaces in the brackets.
It is like html but with [ ] instead of < >
Is this your first week on the internet?

that sort of question is probably better suited to

How do you get the value of a field? Is it just "ent X"?

Please help me. I'm a moron using Haskell.

I'm trying to do a quick workaround to have C-style Char arithmetic ('C' - 'A' == 2) by doing an instance of the Num typeclass

I'm entering this in GHCi, but I'm getting a type error
Prelude Data.Char> instance Num Char where (-) a b = (ord a) - (ord b)

Yep.

No
It's my first week on Sup Forums

where's the code?

that logic seems a bit messed up, but, assuming that the length of s1 after squeeze should always be smaller (or at least different) than before it, it seems you need to mark the end of the string with '\0' at the last position + 1.
so i guess:
s1[k] = '\0';

after the for loop would fix it?

You have to convert back to a Char.

the type of minus is `Num a => a -> a -> a`. So your implementation for `Num Char` becomes `(-) :: Char -> Char -> Char`. There is InstanceSigs extension which lets you write type signatures inside class instances. It's helpful to make sure you know what the expected type is and if you get it wrong, GHC will say the signature is wrong rather than your code.

>mfw you actually delivered
Fair enough. I stand corrected. I'll look into it and see what else you can do with it.

> So your implementation for `Num Char` becomes `(-) :: Char -> Char -> Char`
So is there any way I can do the 'C' - 'A' == 2 thing besides doing the following?
subChars :: Char -> Char -> Int
subChars c1 c2 = (-) (ord c1) (ord c2)


Here's the code I have (wrote it in its own file instead of entering the statement in GHCi)
import Data.Char

instance Num Char where
(-) a b = (ord a) - (ord b)
(+) a b = (ord a) + (ord b)

main:: IO()
main = do
print $ (-) 'C' 'A'

Never mind, I'm stupid.

No. Well, you could redefine the operators to be more flexible but you'd have to ensure that Num is never imported.

Unlike you I never doubted her.

Yes, you just wrote exactly how. Have a function to do it.(-) can only give you back the same type you feed it in the first place.

Also whatever you're doing, doing such arithmetic is almost always wrong but I'm assuming it's just for learning.

>what is web service
>what is CGI

Going into Database programming wondering what's more crucial to focus on, Oracle or SQL?

Tags are like that everywhere.
The only Sup Forums specific part is it is called code.
Also, when you have a problem you want help with, boil it down to a minimal working example where you can reproduce the same error.
Imagine you have a giant project. You wouldn't be able to post it here and nobody wants to read through all your code that has nothing to do with the error in question.
If for nothing else, make it a goal to make a new project in 5 seconds.
You should be able to quickly test stuff or make it easy for people to help you.
Very often, it helps to make the small example, not being able to reproduce it and then read through the code to see what the error is.
If you don't have patience to do that, compile with -g, run the code through a debugger and step through the code to see what is happening.

Have you been programming in the baka approved language, /dpt/?

I'm forced to learn this for my degree (B.S. Informational Systems)

I want to die, there's so much shit.

>c++ for idiots
>it's actually just c
would buy/10

What would a Sup Forums-approved programming language contain?

Absolutely everything.

goto

Raw Pointers and Headers.

JVM Languages or Javascript?
I'm wiling to learn something to get a job.

Sorry I'm fucking retarded
test

>Also, do you have some good style tips for writing readable C++?
use generic lambdas and lambda overload sets to drastically cut down on syntax while still retaining generic/templated functionality. make them constexpr values when they don't capture (i mean the lambda objects themselves - their operator()'s will automatically be constexpr-qualified (and thus also inline-qualified) if applicable. in practice, they often end up behaving like aggressively inlined constexpr functions, all while being concise and readable. and since they're objects, they can be easily passed as arguments to higher-order functions/lambdas/overload sets. as an example, here's a simple/concise implementation of left/right binary fold functions and variadic min/max:

template
struct overload_set : T... { using T::operator()...; };
template overload_set(T&&...) -> overload_set;

constexpr auto foldl = overload_set
{
[](auto f, auto x, auto y) { return f(x, y); },
[](auto f, auto x, auto y, auto... z) { return foldl(f, f(x, y), z...); }
};

constexpr auto foldr = overload_set
{
[](auto f, auto x, auto y) { return f(x, y); },
[](auto f, auto x, auto y, auto... z) { return f(x, foldr(f, y, z...)); }
};

constexpr auto min = overload_set
{
[](auto x) { return x; },
[](auto x, auto y) { return x < y ? x : y; },
[](auto x, auto y, auto... z) { return foldl(min, x, y, z...); }
};

constexpr auto max = overload_set
{
[](auto x) { return x; },
[](auto x, auto y) { return x > y ? x : y; },
[](auto x, auto y, auto... z) { return foldl(max, x, y, z...); }
};

>goto
You mean COMEFROM.
en.wikipedia.org/wiki/COMEFROM

int value(char romanChar) {
switch (romanChar)
{
case 'I':return 1;
break;
case 'V':return 5;
break;
case 'X':return 10;
break;
case 'L':return 50;
break;
case 'C':return 100;
break;
case 'D':return 500;
break;
case 'M':return 1000; //cout

The easiest way to connect the two is through a websocket.
I have used libwebsocket in the past, it is a C library but you can make it work.
On both ends, you define what to do when you receive a message.

Eg, here is my javascript for setting up the websocket:

//WebSocket connection
function connect(websocketServerLocation) {
if (typeof MozWebSocket != "undefined") {
websocket = new MozWebSocket(websocketServerLocation,"simple-protocol");
} else {
websocket = new WebSocket(websocketServerLocation,"simple-protocol");
}
websocket.onopen = function () {
not_connected = false;
};

websocket.onmessage = function (evt) {
received_msg = evt.data;
console.log("Message received = " + received_msg);
dispatcher();
};
websocket.onclose = function () {
not_connected = true;
//try to reconnect in 10 seconds
setTimeout(function(){
connect(websocketServerLocation)
}, 10000);
};
};
//and to send stuff
websocket.send("stuff");

In the HTML, the button will have an onclick function, you set that to the name of the javascript function, just remember everything is a string, so it is probably valid syntax whatever you do.

In C++, you basically follow their tutorial for a simple setup.

so just like c++?

in your function roman_to_int, you call the value function 3 times.
Store the value so you can reuse the result.
int roman_to_int(string measure) {
int total = 0;
int max_value_so_far = 0;
int j = measure.length() - 1;
for (int i = j; i >= 0; i--) {
int result = value(measure[i]);
if (result >= max_value_so_far) {
total = total + result;
max_value_so_far = result;
} else {
total = total - result;
}
}
return total;
}

Precisely.

Thanks. The only thing I really need to do now is to to remove the random value that the non numerlas are assineged to

I'm not sure why the logic i used was messed up, but you;re right I forgot to put the terminating '\0' at the end of string s1.
And it somehow works now...
I would not have guessed that this error in the code was causing this malfunction
hastebin.com/equfaviruh.cpp

If C++ has everything why isn't it used for everything?

Sane string support (so UTF-16).

If C++ has everything, why does it take 10 times as many lines of code to get anything done in it as in any real programming language?

UTF-8 and/or UTF-32 user.

Haskell text package uses UTF-16.

UTF-32 is just as worthless as UTF-16.

But UTF-8 and UTF-32 are useless on any operating systems that counts.

Because it isn't hiding tons of abstractions for your shitty code.

Because brainlets give up learning it and move to some piece of shit language like javascript

t. struggles with any OS other than what his parents bought him

Yak shaving

Had a bug in my game in which characters weren't loading properly. Figured it's most easily solved by migrating code from the client to the client/server shared library, which is a decent size refactoring job. As part of that, I had to ensure the client and server were producing the same random numbers given the same seed, which of course they weren't because fuck you Unity.

Spent my effort today making a copy of .net core's random class, ripping out unsafe code, adding my own functions, and then implementing that all over my project

How does an Operating system bootstrap? I'm just wondering, where does the processor go to find its first instructions? I assume it loads data from disk into address 0x0, and that's the beginining/bootstrap of the OS, but how does it all work? Does anyone have a link I can read about how some specific like an x86 processor begins bootstrapping? Also, if I wanted to just write in x86 assembly WITHOUT an OS, like, write instructions directly to physical memory instead of virtualized memory, how would I go about doing that? Could I write programs to some 2ndary storage, like a CD, and then boot into it from bios?

x86 assembly has everything and it isn't hiding tons of abstractions for your shitty C++ code. Sepples monkeys BTFO.

>need to know Go to install text editor
Too hardcore for me.

...

I used this guy's analysis to help me understand the boot process when I was writing my first OS, it may be useful to you too.
thestarman.pcministry.com/asm/mbr/STDMBR.htm
thestarman.pcministry.com/asm/mbr/MSWIN41.htm

The osdev wiki has a few good pages too

>pascal

there's firmware that gets it started. not instructions that have to be loaded from memory, but ones that are etched into the chip or w/e

It works.
Is there a way that when I print out a num roman statement that the main() won't run so that way no value is printed out?

Are the exercises in pic related often pretty tricky or am I just brainlet?

threadly reminder to study
- artificial intelligence (beyond tensorflow)
- quantum computing
- distributed computing
if you still want a job in 5 years

i started skipping them after a few chapters. i have little time, can't spend it all doing exercises in the books i read. some are much harder than others, yes

You can always be a webdev, bro

he just skims and explains pointers in a dumb way, but good book nonetheless

What jobs exist that aren't webdev anymore? Even if you're writing native code, it's meant to be the backend for some website/webapp. Nobody wants desktop applications anymore since they're difficult to maintain and support on various platforms. Nearly every job is webdev now.

What job do you do that isn't webdev?

good luck competing with indians

embedded software in c

Good luck, user. If you manage to keep your sanity at the end of semester, I'll buy you a drink.

>work in web dev
>work for indians
>low expectations
>writing CRM-CTI integration software
>get 80k right out of college in low COL area
>5 weeks vacation
>parental leave (maternity and paternity)
>401k
>healthcare
>small company so I get to lead my own project

Do it. Work for Indians. It's awesome, it's the easiest job in the entire universe. I leave early every day and never work overtime.

Are you serious? I'm still in CS but even I can tell that there is shit tin of jobs in maintaining, updating, patching adding features to existing software.

consumer software? not much
video games

however, don't rule out software that's meant to run on a server for some website or app
there are tons of jobs that have you write that backend software while someone else does all of the web stuff

So legacy work you mean. There's no work in writing new software that isn't web dev.

All consumer and enterprise computing is over the internet now. Embrace the cloud. Nobody buys native software anymore.

Right that's what I'm talking about. When I say web dev, I include backend software. I'm saying all software dev now involves the web in some way, nobody writes standalone desktop apps anymore and makes money off of it

>Embrace the botnet
ftfy

Why the fuck do I have to learn compiler design for my degree. Who the fuck is writing compilers anymore, LLVM and GCC family run everything now, and if someone really does want to write a compiler they're gonna learn it themselves, not learn it in college.

> GCC family run everything now
Is that Linuxean mafia?

So you can have deeper understanding of tools you're using?

You remind me of all the chads and stacies in high school who keept asking "why do we need to know this" on math lessons

Alright when have you ever had to use calculus? When has anyone that doesn't do scientific/research work had to use calculus?

>never

Admit it: the Chads and Stacies have a better grasp on what ought to be a priority than you do. Chads and Stacies are way better adjusted for life than you

I use calculus every day just by knowing it. With your kind of thinking humanity would still be living in caves

Can I learn programming?
I'm the bad kind of autistic and can't really get my head around how code logic works