[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

/dpt/ - Daily Programming Thread

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 316
Thread images: 25

File: prog.jpg (105KB, 473x496px) Image search: [Google]
prog.jpg
105KB, 473x496px
What are you working on, /g/?

Previous thread: >>61615327
>>
Idris > Haskell > *
>>
kek
Just fuck my shit up, senpai
>>
Learning Scala because $$$
>>
>>61623142
But is it worth your sanity?

https://www.youtube.com/watch?v=uiJycy6dFSQ
>>
>>61623126
What shitlang is this?
>>
>>61623118
This would be true if Idris was ready for production.
>>
>>61623164
>But is it worth your sanity?
I've already lost my sanity by being an Android developer.
>>
Reminder that nobody who posts in /dpt/:

>uses Python
>is male
>thinks OOP is a good thing
>likes Electron apps
>>
>>61623173
Top tier reading comprehension, m9
>>
>>61623187
My condolences fampai
>>
>>61623173
you know it's shit when they have to call functions procedures for no reason other than to be different
>>
>>61623220
Procedure used to be the common term as opposed to a function which is a mathematical entity that has no side effects. It is planned to have func as syntactic sugar for proc {.noSideEffect.} and func is already a keyword. Naming it def would not make sense because Nim also provides an iterator and a method keyword, whereas def stands for define.
>>
How do people get Microsoft mvps? Is it worth it?
What about Oracles certs
>>
>>61623225
nobody cares, just kill yourself already
>>
File: 1455954055666.jpg (49KB, 600x900px) Image search: [Google]
1455954055666.jpg
49KB, 600x900px
>>61623248
>>
>>61623231
When interviewing people I have never cared how many Microsoft/Oracle certs they have
>>
>>61623298
Do you carre about WPM?
>>
>>61623316
Only to the extent that your typing speed doesn't stop you from getting things done.
>>
>>61623218
It's OK anon. I get my daily laughter during merge requests.
>>
>Kind of want to program
>Nothing I want to program

fuck
>>
>>61623377
Are you me.
>>
File: 1501286820087.jpg (137KB, 403x403px) Image search: [Google]
1501286820087.jpg
137KB, 403x403px
>>61623104
Is there any documentation editor that would produce something as simple as this? could be also a markdown editor that has an automatic table of contents.

http://surjithctly.github.io/documentation-html-template/
>>
>>61623298
Yeah, I interviewed a bunch myself, never asked
Was just wandering if that's a big deal, we are a small company
>>
>>61623377
Do bugfixes for open source shit on git?
>>
File: 1500697638815.png (91KB, 640x480px) Image search: [Google]
1500697638815.png
91KB, 640x480px
Realisticly speaking, how long would it take to code a DOS level kernel in C, having plently of prior experience with programming but none with kernels directly?
>>
>>61623607
Take a look at the FreeDOS project, even a simple real mode OS is a lot of work if you want actual functionality
>>
>>61623607
the phrase "dos level kernel" shows you don't even have a primary understanding of operating systems
>>
File: 1501033496696.jpg (101KB, 1280x720px) Image search: [Google]
1501033496696.jpg
101KB, 1280x720px
>Takes string
>Reverses it
>Checks if palindrome

What do you think?

#include <iostream> 
#include <vector>
#include <locale>

std::vector <char> stringToVec(std::string inputString) {
std::vector <char> letters;
for (int a = 0; a < inputString.size(); a++) {
letters.push_back(inputString.at(a));
}
return letters;
}

std::string vecToString(std::vector <char> inputVec) {
std::string reversedString("");
for (int a = 0; a < inputVec.size(); a++) {
reversedString.push_back(inputVec.at(a));
}
return reversedString;
}

std::string cleanString(std::string inputString) {
std::locale loc;
for (std::string::size_type i = 0; i < inputString.length(); i++) {
inputString[i] = std::tolower(inputString[i], loc);
}
for (std::string::size_type i = 0; i < inputString.length(); i++) {
if (inputString[i] == ' ') {
inputString.erase(i, 1);
}
}
return inputString;
}

std::string checkPalindrome(std::string reversedString, std::string originalString) {
if (cleanString(originalString) == cleanString(reversedString)) {
return "Yes";
}
return "No";
}

std::vector <char> reverseVec(std::vector <char> inputVec) {
std::vector <char> reversedReturn;
for (int a = inputVec.size() - 1; a >= 0; a--) {
reversedReturn.push_back(inputVec.at(a));
}
return reversedReturn;
}

int main() {
std::cout << "Enter the string you would like reversed: ";
std::string userInput("");
std::getline(std::cin, userInput, '\n');
std::string reversedInput(vecToString(reverseVec(stringToVec(userInput))));
std::cout << "Reversed: " << reversedInput << std::endl;
std::cout << "Palindrome: " << checkPalindrome(reversedInput, userInput) << std::endl;
return 0;
}
>>
>>61623683
Too many unnecessary copies, read about references.
>>
>>61623683
This is either bait or homework shit, get the fuck out.
>>
>>61623683
In Haskell, this is just

palindrome s = s == reverse s
>>
>>61623683
Also, this is the first time in years I see someone using 'locale'.
>>
>>61623683
Here is the equivalent Haskell:
(ignoring main)

palindrome = (==) <*> reverse
>>
>>61623694
>unnecessary copies
What are those

>>61623702
>homework shit
Its not this is legit my solution to what I said

>>61623712
idk dude im just looking at random shit on this site http://en.cppreference.com/w/
>>
> C++14
> g++
>Loonix
>code with <thread>

shit doesn't compile
> undefined reference to `pthread_create'
> collect2: error: ld returned 1 exit status

first of all, why? <thread> is supposed to be part of the standard
>>
>>61623729
add -pthread to the compiler flags
>>
>>61623683
const bool is_palindrome(const std::string &s)
{
return s == std::string{s.rbegin(), s.rend()};
}
>>
>>61623683
Use std::string_view to accept string parameters.
>>
https://github.com/majestrate/XD

needs a logo maybe /g/ can help
>>
>2017
>still no haskell microkernel
>>
>>61623720
>>61623743

You do realize that this won't work for something like:
"A new order began a more Roman age bred Rowena"
>>
>>61623683
This girl wrote his own game engine and you can't even write a proper palindrome tester.
>>
>>61623729
why the fuck are we still supposed to do this when the include speaks for itself?
> -pthread
> Adds support for multithreading with the pthreads library. This
> option sets flags for both the preprocessor and linker.
>>
>>61623755
>Garbage collected kernel
This is as bad as when Microsoft attempted to write a managed kernel to replace NT.
>>
>>61623760
Except it works so I don't understand why you say it is not proper.
>>
>>61623761
#include doesn't link against any libraries. It just copy and pastes header files into your source file.
>>
>>61623755
>2017
>not contributing to Rust microkernel
>>
>>61623759
ok?
const bool is_palindrome(std::string s)
{
std::transform(s.begin(), s.end(), s.begin(), ::tolower);
return s == std::string{s.rbegin(), s.rend()};
}
>>
>>61623759
palindrome `on` map toLower
>>
>>61623759
import Data.Char (toLower)

palindrome s = s == reverse $ map toLower s
>>
>>61623791
>2017
>contributing to a dead project in a dead language
>>
>>61623760
>his

>>61623791
Redox is trash. Haiku is way better, and it's written in a much better language too.
>>
>>61623786
I get it but gcc is supposed to know what to do

<thread> is C++11, not some new experimental contraption from C++17
>>
>>61623801
you need to lower both strings
>>
>>61623792
>>61623799
>>61623801
Except you fail to take into account the spaces.
Second time you fags have failed
>>
>>61623759
That's not even a palindrome.
>>
File: bury him.png (43KB, 516x546px) Image search: [Google]
bury him.png
43KB, 516x546px
>>61623805
>>
>>61623819
Yes it is
>>
>>61623808
>I get it but gcc is supposed to know what to do
What the fuck do you mean? I just fucking told you, #include just copies and pastes shit into your source files. Retard.

>>61623836
No it isn't. What, you think spaces don't exist or something?
>>
>>61623812
partition `on` (map toLower . filter (not . isSpace))
>>
>>61623812
>keep radically changing the specs (inb4 >you didnt even test my autistic 905049560386 line C++ program)

>only slightly increases the length of the Haskell one-liner
>>
>>61623812
Who cares, we're not here to solve your homework, merely showing that it doesn't require a 100 lines of code solution.
>>
>>61623820
What am I looking at?
>>
>>61623873
a haiku
>>
>>61623845
>#include just copies and pastes shit into your source files.
why the fuck do you have to add special compiler flags for standard code to compile?

you can pretend that it makes sense if it makes you feel better but it's bullshit
>>
>>61623863
He only added one line in the C++ example, wtf are you talking about.
>>
>>61623873
a Chinese poem about /g/ attitude to the Rust language
>>
>>61623891
we're talking about >>61623683
>>
>>61623885
It's not bullshit, it makes complete fucking sense.
<thread> uses pthreads and therefore relies on the pthread library. You think <thread> is fucking magic or something? You need to link against the fucking pthread library you moron.
>>
>>61623760
Writing a game engine takes a day if its simple you pompous fuck
>>
>>61623896
>/g/
I should say dudebro attitude in general
>>
>>61623683
kek
So this is the power of c++
>>
>>61623917
No, that guy is just really fucking shit.
It would be so much worse in C.
>>
>>61623807
C++ is worse than Java
>>
>>61623906
you always have to link against something you fucking moron

do you know what libstdc++.so is? DO YOU MANUALLY LINK TO IT AND ALL THE OTHER SHIT??

just shut the fuck up.
>>
>>61623924
>that guy is just really fucking shit
I really don't understand why you say this. What is inherently wrong about the code.
>>
>>61623908
This cat kind of looks like Assad
>>
>>61623935
>DO YOU MANUALLY LINK TO IT AND ALL THE OTHER SHIT??
actually yes, you do
>>
>>61623926
C++ is orders of magnitude better than Java.
Java literally has no place in software development, C++ does a better job at literally everything that Java and even C does.
>>
File: 1491078221856.png (665KB, 768x1024px) Image search: [Google]
1491078221856.png
665KB, 768x1024px
>>61623720
>>61623799
>>61623849

as you can see, Haskell code can easily adapt to changing requirements and is almost modular in a way
>>
>>61623938
Performance and readability
>>
>>61623947
with includes ... >>61623808


you fucking moron.
>>
File: 1498022934481.jpg (781KB, 1188x990px) Image search: [Google]
1498022934481.jpg
781KB, 1188x990px
>>61623945
It is Assad you fucking nit show some respect
>>
>>61623948
Java has modules, C++ doesn't. All it does is that it opens the flood gate for fucktards like you into systems programming
>>
>>61623966
I don't think the standard specifies this so this is valid behavior
>>
>>61623967
Oh, wow! I'm so sorry.
>>
>>61623935
libstdc++.so is automatically linked against unconditionally.
You're saying that GCC should automatically link against libpthread.so when <thread> is included.
So I ask you, why the fuck should GCC introduce this shitty hack? What if I'm freestanding and I create a header file called thread and include it? It'd link against an unwanted library.
>>
>>61623986
>What if I'm freestanding and I create a header file called thread and include it?
like gcc doesn't know which thread you're including

at least stfu after you got owned.
>>
>>61623986
Requiring external libraries to build stuff in the std namespace is just laughably bad.
>>
Why should pthread be a part / dependency of libstdc++?
Why should pthread be linked into binaries that don't even want to use threads?
>>
>>61623683
>>Takes string
>>Reverses it
>>Checks if palindrome
import std.stdio, std.algorithm, std.string;

void main(string[] args)
{
string input;
while ((input = readln.strip) !is null)
input.is_palindrome.writeln;
}

bool is_palindrome(in string s)
{
auto rs = s.dup;
rs.reverse();
return s == rs;
}
>>
>>61624047
Man, I wish D was more popular.
>>
Imagine using a language that doesn't support parallelism using threads
>>
>>61623979
>Java has modules, C++ doesn't
Yet it still manages to be better. When C++ gets modules and concepts in the next revision, Java and C# will be severely blown out of the water for good.
>>
>>61624061
Why? It's not very good.
>>
>>61624047
auto is_palindrome = function (string s) => s.dup.reverse == s;
>>
>>61623759
It also fails for "σοφός", say, but good luck fixing that.
>>
>>61624076
It's already a huge improvement over C++, and Andrei is the man.
>>
>>61624016
>like gcc doesn't know which thread you're including
How is it going to tell?
>>
>>61624074
>When C++ gets modules
Then it will have both header files, and modules. Enjoy your shitty C preprocessors and maintaining both modules and header files, ratard
>>
Remember monads are the real solution to many problems and superior to ad-hoc solutions found in several languages

https://philipnilsson.github.io/Badness10k/posts/2017-05-07-escaping-hell-with-monads.html
>>
>>61624047
And your point is?

If literally any of you fags just read the code you would see that the actual checking of palindrom is this:

std::string cleanString(std::string inputString) {
std::locale loc;
for (std::string::size_type i = 0; i < inputString.length(); i++) {
inputString[i] = std::tolower(inputString[i], loc);
}
for (std::string::size_type i = 0; i < inputString.length(); i++) {
if (inputString[i] == ' ') {
inputString.erase(i, 1);
}
}
return inputString;
}

std::string checkPalindrome(std::string reversedString, std::string originalString) {
if (cleanString(originalString) == cleanString(reversedString)) {
return "Yes";
}
return "No";
}


Which isn't long considering it lowers the case of all letters, removes all space, and checks for equality.

>>61624087
I don't give a fuck about this
>>
>>61624046
Why should C++ still use this garbage linkage model?
>>
>>61624046
>Why should pthread be linked into binaries that don't even want to use threads?
It isn't. If you don't use <thread>, you don't need to link against libpthread.so
>>
>>61624107
>f literally any of you fags just read the code
I'd rather look at horse shit than the abomination you are posting. Your function description is stated in 3 lines and that's what I did
>>
>>61624116
whomst are you quoting, friend?
>>
>>61624107
Why are you returning 'Yes' and 'No'?
>>
>>61624151
OOP
>>
File: helpMeG.png (150KB, 1920x1080px) Image search: [Google]
helpMeG.png
150KB, 1920x1080px
I am writing C++ in Visual Studio Community 2017 on windows 10 and my code is perfect but all these random ass errors are popping up that tell me it can't open the source file..
I was wondering if any of y'all know the solution to my problem.
Sorry for shitty color scheme rn I am not worried about it
>>
>>61624087
>σοφφοσ
hmm
>>
>>61624164
Perhaps it wants you to use cfloat, cmath and the likes in C++ mode, but this is only a guess.
>>
File: unit testing framework.jpg (52KB, 600x373px) Image search: [Google]
unit testing framework.jpg
52KB, 600x373px
>>61624172
>D can't even handle input properly
>>
>>61623683
>>61624107
Thanks for reminding me of the cancer that's called C++
>>
>>61624192
What do you mean?
>>
>>61623126
This compiles:
proc addit[T, U] (a: T, b: U): auto =
return U(a) + b

proc main() =
echo addit(12, 22.1)

main()

Therefore it appears Nim does not support implicitly converting ints to floats.

Not gonna lie, that's pretty awful.
>>
>>61624161
Wut? What's that got to do with it? Just return true/false like everyone else on the planet.
>>
>>61624215
No, that's not a bad thing. However unlike Rust, it is inconsistent about implicit conversion, which is bad.
>>
>reversing the string to check equality
fucking pajeets
>>
>>61624227
C++ is corrosive to brain
>>
>>61624107
;-)
const bool is_palindrome(std::string s)
{
s.erase(std::remove_if(s.begin(), s.end(), ::isspace));
std::transform(s.begin(), s.end(), s.begin(), ::tolower);
return s == std::string{s.rbegin(), s.rend()};
}
>>
>>61624047
#include <iostream>
#include <string>

bool is_palindrome(const std::string &str) {
return str == std::string(str.rbegin(), str.rend());
}

int main() {
std::string line;
std::getline(std::cin, line);

std::cout << is_palindrome(line) << '\n';
}


D btfo.
>>
>>61624260
this is shit, just do pointer arithmetics
>>
>>61624235
Not supporting implicit conversion is in most cases a boon. But when it goes so far as not supporting implicit conversion between ints and floats, that's just plain awful. On this I will not budge.
>>
>>61624260
>>61624083
C++ eternally BTFO
>>
>>61624139
Fucking kill yourself, retard.
>>
>>61624251
;-)
int is_palindrome(char *s) {
for (char *t = s + strlen(s) - 1; t > s; t--, s++)
if (*t != *s) return 0;
return 1;
}
>>
>>61624322
>int
>strlen
disgusting
>>
>>61624290
>tfw you made posts in both languages
>>
File: are-you-wizard.jpg (39KB, 500x664px) Image search: [Google]
are-you-wizard.jpg
39KB, 500x664px
can i check if a decimal number is a palindrome using something similar to the beautiful bitmask method for binary numbers
>>
>>61624340
>disgusting
objectively wrong
>>
>>61624345
Why not check if a program's binary is a palindrome?
>>
>>61624251
>return s == std::string{s.rbegin(), s.rend()};
return std::equal(s.begin(), s.begin()+s.size()/2, s.rbegin(), s.rbegin()+s.size()/2);
>>
>>61624172
>UFCS
Why do people like this?
>>
File: 7b3043d5bad70cbc60d8c0e73c94a997.jpg (491KB, 1100x1320px) Image search: [Google]
7b3043d5bad70cbc60d8c0e73c94a997.jpg
491KB, 1100x1320px
Can someone repost that chart with programming exercises?
>>
>>61624366
Do(you(have(some(kind(of(autism(?))))))
>>
>>61624366
UFCS is great as long as you're not a paren-dropping nigger.
>>
File: 1470429691306.png (74KB, 300x256px) Image search: [Google]
1470429691306.png
74KB, 300x256px
>>61624371
just google programming exercises like bruh them shits are all over the internet
>>
>>61624322
I like this.
It's very clear.
But it does t strip the whitespace or lower the case like the C++ version.
>>
>>61624363
quine-like challenge:
write a program whose object code will be a palindrome, and will be able to verify this about itself at runtime
>>
>>61624371
No. And I know full well you are the one who makes this shitty chart
>>
>>61624371
no, it serves no purpose other than making people shit up the thread
bookmark https://better-dpt-roll.github.io/ instead

>>61624364
fair enough

>>61624290
>>61624343
also technically if we only care about reverse without stripping/lowering like in D case the C++ one can be also written as:
auto is_palindrome = [](const std::string &s) { return std::string{s.rbegin(), s.rend()} == s; }


slightly more verbose
>>
>>61624305
go back to /r/programming, please
>>
>>61624371
>>
I want to create a fidelity app to my mom's coffee shop so people can get discounts if they buy there enough or if they pay upfront.

How should i go about it?
>>
>>61624421
Cancer
>>
redpill me on /r/programming
>>
>>61624377
If what you do is call functions on the returns of other functions enough that you'd invent a syntactic convenience for it I'm not sure I value your opinions.
>>61624382
Parens would be nice to distinguish functions from member fields in languages that use that.
>>
>>61624421
Thank you
>>61624403
>>61624399
>>61624390
Sorry, I'm new to this stuff and didn't know where else to ask
>>
>>61624430
How should anyone here know anything about that? Go to /r/programming and ask.
>>
>>61624418
What the fuck is wrong with you? Are you brain damaged?
I think the one who needs to go back to plebbit is you. Fucking moron.
>>
>>61624441
>If what you do is call functions on the returns of other functions
So, basically everyone?
>>
File: 1496291446995.jpg (2MB, 1920x1080px) Image search: [Google]
1496291446995.jpg
2MB, 1920x1080px
>>61624429
Only wanted to give it to the other anon since none of you other people delivered.
>>
>>61624441
Exactly right. This is also why I hate properties.
>>
>>61624471
I am a 1337 hacker master, I don't use functions.
>>
>>61624471
You need to work on your attention span. Find the enough...
Also no most programmers i know write code not function calls.
>>
what is your opinion on code golf
i see people itt somewhat jerking over shorter implementations of something using another language
>>
>>61624460
Btw anon for the programming challenges litereally just google "/g/ programming challenges" and you will find it :)
>>
>>61624490
Can you write a Kelvin to Celsius converter without function calls?
It should be straight forward to you
>>
>>61624192
That picture is wrong. It seems to be intended to entail this is why unit testing is bad, but that's wrong. In reality, whoever designed the unit tests on that boat was bad, not the practice of unit testing itself. There should have been numerous unit tests at the submerged end of the ship, which, being thus submerged, would have failed, and then the problems leading to their failure would have been fixed
>inb4 after that there just would have been more problems
1) Not if the structure of the code you write has a clear, logical, and self consistent relationship to the unit tests you're trying to make it pass, as it should.
2) Regardless, unit tests should cover literally every possible surface of end user functionality. If there are holes in the test fabric, then yes, there may be problems lurking there, but there should be no holes. That ship should be completely covered in green circles, and the submerged ones should be red, as well as no less dense.
>>
>>61622383
Yup.
I've always wanted to program something like that, but then I actually searched and someone made it before me.

It's pretty great.
>>
Who /programming while holding in a massive crap/ here

>>61624491
Cool way to have fun but not really useful
>>
>>61624524
He's not going to answer this, because he knows he's not going to win this "argument"

gg
>>
File: baka.jpg (7KB, 225x225px) Image search: [Google]
baka.jpg
7KB, 225x225px
Who drunk programming?
>>
>>61624403
>slightly more verbose
That looks cancerous
>>
>>61624571
>Who /programming while holding in a massive crap/ here
That's a pessimistic way of looking at your programs
>>
>>61624597
Sounds fun, I should try it out some time
>>
>>61624586
writing kelvin to celcious converter with macros is pretty easy assuming your language support macros.
>>
>>61624398
Sounds fun and terrifying
>>
File: 1485764233138.png (372KB, 954x768px) Image search: [Google]
1485764233138.png
372KB, 954x768px
>>61624382
What's wrong with paren-dropping again?
>>
>>61624597
In about 2 hours
>>
>>61624676
So where's your converter, I don't see any
>>
>>61624683
dumb r*dditposter
>>
>>61624705
Exactly
>>
>>61624597
The only time I got even half drunk, I hated the feeling. Way too dizzy and I never felt like it helped "open my thought processes" or whatever the hell other people get out of programming while drunk.
>>
>>61624703
do your own homework
>>
>>61624683
if you think data is code you should go back to lisp
>>
>>61624720
No, no. I can't do my homework without function calls, I'm here to see how expert /g/ programmers do it without functions
>>
>>61624722
if you think code is not data you should kys
>>
>>61624722
It isn't? I've never written a line of LISP in my life though
>>
>>61624735
https://www.theregister.co.uk/2017/06/16/texting_teen_guilty_of_manslaughter/
>>
>>61624683
dumb frogposter
>>
>>61624751
i withdraw my statement
>>
>>61624771
I thought frogposting is deemed "uncucked" by cool right wing boys
>>
>>61624804
>by cool right wing boys
go back to the_donald fucko
>>
>>61624804
No, frogposting is reddit material.
4chan is a weeaboo nationalist imageboard.
Left/right and politics are unimportant.
Anime is important.
>>
>>61624676
>needing even macros to add or subtract 273.15 degrees
>>
>>61624829
>add or subtract
What are those?
>>
>>61624597
I cant program drunk but I take after the Morrowind lore development and draw or write setting material while blitz'd
>>
>>61623187
Android studio is shit
>>
>>61625137
what's a better alternative?
>>
>>61624722
All data is code but not all data is useful code that won't crash
>>
>>61624428
I assume it's a small shop. Just set up a n o d e j s server with mongodb. Use some basic hashing algorithm for passwords. Shouldn't take more than a couple days if you've never touched both before, one night otherwise. Use an old PC or laptop and make sure it's up during working hours at least. You can make the app keep last seen data offline or stuff like that too for usability.
If you know Java, you can make a native android app with 1 login activity (view) and 1 normal activity for adding the code and showing fidelity points or something in under 1 week. You can keep the user logged and even spam them with push notifications if you're feeling scummy. Don't try to push ads though.
gaiOs is another thing. I think you can use C/C++ with it, but you definitely need to do the interface in swift and objective-c. Sucks big time.
If your mom has a website, it shouldn't bee too difficult to include some requests to your server and a form and some buttons. Gets complicated if she currently has no login/cookies system, otherwise one night should be enough.
All of the above taking into account a full time day job.
>>
A todo aop as an example of a CRUD application using spring and node.js
>>
#include <stdio.h>

void foo(char array[static 1]) {
puts(array);
}

int main(void) {
char array[6] = "hello";
foo(array);
}


I though I knew C. Turns out I'm a brainlet.
>>
>>61625177
>Use an old PC or laptop and make sure it's up during working hours at least.
I'd say it's not worth the hassle and if they run a business he should opt in to getting something like a $5 VPS/mo from DO/Linode which would guarantee 99.9% uptime without having to worry about power outages, ISP fucking up, or the hardware failing.
>>
>>61625200
I think that's pretty understandable, the parameter decays to a char pointer and puts prints out until the null terminator.
>>
>>61625177
well, i have little experience in programming but i'll give it a look.

not gonna be scummy, i just need something to incentivise people to spend more there.
>>
>>61625223
>i just need something to incentivise people to spend more there.

- make the place more attractive.
- give discounts like pay 2, get 3
- client cards for customers. after it has been used 50 times give a free round
>>
>>61625220
void foo(char array[static 1]);


means that foo takes an array of *at least 1* element. This can be used for optimization and warnings, it's valid code and I didn't know you could use static like that.

I'm coding in C for 2 years now, it's a small language and I still don't know it.
>>
>>61625200
>[static 1]
Huh.
That's a pretty cool feature.
Never knew about it.
>>
>>61625251
yeah, that's pretty much the idea.

give points if they buy stuff there, give them free stuff if they buy in bulk and give more stuff if they go there regularly.
>>
>>61625255
>*at least 1*
huh, interesting
>>
>>61625255
wow C is bloated trash
>>
>tfw you learn of
makecontext
/
swapcontext


What's /dpt/'s favorite coroutine implementation?
>>
>>61625322
>wow C is bloated trash
less-bloated alternative?
>>
File: ProgrammingChallenges, 4.0 (HD).png (2MB, 3840x2160px) Image search: [Google]
ProgrammingChallenges, 4.0 (HD).png
2MB, 3840x2160px
>>61624371
This one?
>>
>>61625329
conduit and other haskell libraries do some pretty cool stuff
>>
>>61625255
Don't see why you need the static. You get the same semantic without it.

It's weird that this does not affect sizeof(), which will still give you the size of the pointer instead of the size of an array with the given number of elements. i.e.

void foo(char bar[2]) {
char baz[2] = "a";
//sizeof(bar) != sizeof(baz)
}
>>
>>61625355
Static makes a *promise for the compiler* that the programmer won't pass an array less than that. So passing an array less than specified size is undefined behaviour (with static).

In your example, it's completely equivalent to void foo(char *bar) and makes no promises to the compiler.
>>
>>61625395
I might have explained it badly.
void foo1(char *bar);
void foo2(char bar[2]);
void foo3(char bar[static 2]);

are all equivalent except that passing an array of less than sizeof(2) is undefined behaviour.

So foo3(NULL) is undefined while foo1(NULL) and foo2(NULL) is ok.
>>
>>61625454
So none of these do compile time checks?
>>
>>61625545
foo3 might print a warning if a non-array is passed to it. The warning is not mandated by the standard. Newest versions of clang print the warning, I don't know about GCC.
>>
>>61625571
I mean if array passed to foo3 is not char[>=2]
>>
>>61625585
Speaking about more cool less known features, C11 added static (compile time) asserts and generic macros.
>>
Anyone with experience with python's unittest?

Everywhere I search it says that the variables I've declared are supposed to return to the original value between the tests.
But my second test fails because I've changed the variable on the first test.
If I comment the first test, the second one passes...

Any idea why?

import unittest

from grid import Grid

class TestGrid(unittest.TestCase):
GRIDLIST_2x2 = [[1, 2],
[3, 4]]

GRIDLIST_3x3 = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]

def test_init(self):
original = self.GRIDLIST_2x2
grid = Grid(original)
original[0][0] = 0

self.assertNotEqual(list(grid), original)
self.assertEqual(list(grid)[0][0], 1)

def test_transpose_2x2(self):
EXPECTED = [[1, 3],
[2, 4]]

expected = Grid(EXPECTED)
grid = Grid(self.GRIDLIST_2x2)

self.assertNotEqual(grid, expected)
self.assertEqual(list(grid), list(expected.transpose()))
self.assertEqual(grid.transpose(), expected)

if __name__ == '__main__':
unittest.main()
>>
>>61625610
>generic macros.
It resembles function overloading more than "generics".
>>
>>61625634
still cool. Also it introduced unnamed structs and unions, I use them day to day.

I would like it if they put auto for type inference in C22.
>>
>>61625617
in the docs i just see
https://docs.python.org/3/library/unittest.html#unittest.TestCase.setUp
>>
>>61625663
>auto for type inference in C22.
PLS FOR THE LOVE OF GOD NOOOOO!
If they are going to implement type inference they could actually do it properly.
>>
>>61625663
It's cool. but it can lead to some unintuitive behavior since C is so weakly typed.
That's also the reason I don't think type inference would fit in C.
auto my_char = 'x'; // -> int
>>
>>61623104
>he prefers to use P*thon
get the fuck out of my thread and never return. i hate a Pyn*ggers so fucking much.
>>61625617
>Python
Hi. I hate you.
>>
>>61624403
To have equivalent functionality to D, you would need to have proper multibyte string handling.

#include <string>    
#include <iostream>
#include <locale> // setlocale
#include <algorithm> // remove_if, transform
#include <cstring> // strlen

bool is_palindrome(std::wstring s) {
s.erase(std::remove_if(s.begin(), s.end(), std::iswspace), s.end());
std::transform(s.begin(), s.end(), s.begin(), std::towlower);
return std::equal(s.begin(), s.begin()+s.size()/2, s.rbegin(), s.rbegin()+s.size()/2);
}

std::wstring mb_to_wstr(const char* ptr) {
std::wstring str;
std::mbtowc(NULL, 0, 0);
const char* end = ptr + std::strlen(ptr);
int ret;
for (wchar_t wc; (ret = std::mbtowc(&wc, ptr, end-ptr)) > 0; ptr+=ret) {
str.append(1, wc);
}
return str;
}

int main()
{
std::setlocale(LC_ALL, "en_US.utf8");
std::cout << is_palindrome(mb_to_wstr("Foo 株セ 株ooF")) << '\n';
std::cout << is_palindrome(mb_to_wstr("σο φfφοσ ")) << '\n';
return 0;
}
>>
>>61625690
>If they are going to implement type inference they could actually do it properly.
How would they do it without breaking old code? By introducing a new _UnderscorePrefixed keyword and a new header to prettify it? You think that's better? C++11 brought it and people liked it. By diverging from C++ we would be further breaking the ecosystem and giving market to abominations like C# and Java.
>>
Do you think the human mind is functional or object oriented?
>>
>>61625791
It's a neural network.
>>
>>61625791
a mix of the former and of neither
>>
>>61625715
Are you sure this is going to be an integer? I can't find a standard reference. Still looking.
>>
>>61625791
object oriented in that we understand things as objects, not just data
functional in that we think declaratively and use pattern matching
>>
Why aren't you using a language with continuations?
>>
>>61625839
http://en.cppreference.com/w/c/language/character_constant
>Such constant has type int

C++'s major breaking changes mainly pertain to the type system. This is why.
>>
File: nigggaaaa.jpg (53KB, 730x974px) Image search: [Google]
nigggaaaa.jpg
53KB, 730x974px
>>61624597
I tried it once, I ended up just listening to vaporwave and feeling depressed.
>>
>>61625847
What are you suggesting?
>>
>>61625902
Scheme
Haskell
>>
>>61625883
Well once you had more than you need you start to get distracted easily. So usually what I do is if I know today I'm implementing something that I kind of understand and know what I'm doing then I will drink.
If you are not too sure what you want to do or how to do it you will just find execuse to get away from programming.
>>
>>61625915
I use Haskell where possible
>>
>>61625923
Good, keep an eye on Idris for the future
>>
Any decent learning resources that explore Windows API programming apart from the official API?
>>
>>61625969
just use electron lol
>>
>>61625950
It's dead, Jim.
>>
>>61625873
Holy shit, I learned some more new C stuff today.

#include <stdio.h>
int main(void) {
int cstr = 'yes';
switch (cstr) {
case 'yes': puts("yes"); break;
case 'no': puts("no"); break;
default: puts("dunno");
}
}


This is implementation-defined though, so not very useful. I don't know if the standard guarantees that all 2 letter character strings are going to be unique.
>>
>>61623498
As soon as I'm halfway through the fix Ind1anHaker425 has already git pushed his one line solution
>>
>>61625972
heh
>>
>>61625989
found an article on them:
http://www.zipcon.net/~swhite/docs/computers/languages/c_multi-char_const.html
>>
>>61624322
>>61624394
int is_palindrome(char *s) {
while (*s && isspace(*s)) ++s;
char *t = s + strlen(s) - 1;
while (t > s && isspace(*t)) --t;
while (t > s) {
if (tolower(*s) != tolower(*t)) return 0;
do { ++s; } while (t > s && isspace(*s));
do { --t; } while (t > s && isspace(*t));
}
return 1;
}
>>
>>61626103
*&><==&*%
>>
>>61624586
Actually I wasn't gonna answer it because it's obvious bait, completely ignoring the point I'm making and making a statement completely orthogonal to the idea I was presenting.
But I didn't see it until now.
>>
>>61626103
not proper c++
>>
>>61624322
>>61626103
>strlen
Inefficient as fuck.
>>
>>61624340
Faggot.
>>61624322
>>61626103
Nice.
>>
>>61626139
What's improper about it?
>>
>>61625989
uint64_t firstname = *(uint64_t*)"ZOOSMELL";
uint64_t lastname = *(uint64_t*)"POOPLORD";
>>
>>61626140
I agree. This function should take a length argument. If the calling code wishes to strlen they can do that.
>>
>>61626154
This is old stuff. It's just simple casting.
>>
>>61626140
It may surprise you to know that using strlen here is actually more efficient than manually scanning character by character for a null terminator.
>>
>>61626178
It's still O(n).
The string length should already be available.
>>
>>61626178
Go on?
>>
>>61626154
>>61626173
I must admit the first thing that popped in my mind when I found and that multi-character character constants are valid in C is Terry and HolyC in his "The Hardest Question in Programming" tutorial.
>>
>>61626162
>I agree. This function should take a length argument.
I'm not sure I agree with this. I do agree there should be a more efficient version that takes a length argument, and that version should be called is_n_palindrome, following the convention of such function pairs as strlen versus strnlen and strcpy versus strncpy.
>>
>>61626189
The problem itself is O(n), who gives a fuck about the constant factor lol!
>>
>>61626190
strlen has machine dependent optimizations.
>>
need scripting language for muh C program. Can't be lua because end and can't be scheme because fuck scheme.
Is there actually good scripting language?
>>
>>61626236
cscript
>>
>>61626190
The standard library string functions are word-optimized. Of course, strlen does indeed linearly scan for a null terminator, but what makes it more efficient is that it does it int by int, instead of char by char. It uses some obtuse bitwise magic to efficiently determine whether any byte of the int is null without having to check each byte.
>>61626189
see: >>61626206
>>
>>61626236
>Can't be lua because end
Caring about such semantic nitpitcks when there are so much bigger holes in the language

Anyway, what kind of fizzbuzz that needs a scripting language you are writing?
>>
>>61626257
bloat
>>
>>61626257
Clever.
>>
>>61626286
Just because you're a brainlet that can't understand such simple code it doesn't mean it's bloat, dear.
>>
File: installing rust.jpg (68KB, 855x470px) Image search: [Google]
installing rust.jpg
68KB, 855x470px
am I doing it right?
>>
>>61626359
>Windows
>Rust
Yes, you are doing it right.
>>
>>61626236
fuck off, if you're going to be arbitrarily picky then no, there aren't any "good" scripting languages
>>
>caring about an extra strlen in an already O(n) problem
You guys are fucking hopeless
>>
>>61626257
>obtuse bitwise magic
kek
can this be an official industry standard acronym for talking about boilerplate code from now on
"it's pretty efficient but there's a lot of undocumented OBM that could stand to be cleaned up"
>>
>>61623104
Do you know any good tutorials/books/whatever to learn WPF?

I would like to make a GUI for a little program made in C# but I have no fucking idea about where to start.
>>
Has anyone here worked with Spark (the Java web framework)? I've been reading through the docs and SO, but I haven't found a decent answer yet.

How are you supposed to deploy a Spark application the right way? Ideally without building it on the server.
>>
>>61626103
>while (*s && isspace(*s))
This can be simplified to
while (isspace(*s))
because the null terminator character is not considered whitespace
I certainly don't blame you for missing this small detail since it just shows you're too used to being careful about bounds checking which is always a good thing
>>
>>61626475
Use a container
>>
>>61626490
Assume I have a container. What should I put where *in* the container?
>>
>>61626498
>the sock ruse was a............
>DISTANCTION

>i HAVE the container
>>
import palindrome
print is_palindrome(string)

pfft
>>
// Binary I/O library

#ifndef BIO_H
#define BIO_H

#include <stddef.h>
#include <stdint.h>

typedef struct { // File structure, supposed to be private but oh well
size_t n, i, m; // File size, current index, allocated memory size
void *b;
} BioFile;

BioFile *bioOpen(const char *path, const char *mode);
void bioClose(BioFile *file);

void bioWriteU8(BioFile *file, uint8_t u8);
void bioWriteS8(BioFile *file, int8_t s8);

uint8_t bioReadU8(BioFile *file);
int8_t bioReadS8(BioFile *file);

void bioWriteU16LE(BioFile *file, uint16_t u16);
void bioWriteS16LE(BioFile *file, int16_t s16);
void bioWriteU32LE(BioFile *file, uint32_t u32);
void bioWriteS32LE(BioFile *file, int32_t s32);
void bioWriteU64LE(BioFile *file, uint64_t u64);
void bioWriteS64LE(BioFile *file, int64_t s64);

uint16_t bioReadU16LE(BioFile *file);
int16_t bioReadS16LE(BioFile *file);
uint32_t bioReadU32LE(BioFile *file);
int32_t bioReadS32LE(BioFile *file);
uint64_t bioReadU64LE(BioFile *file);
int64_t bioReadS64LE(BioFile *file);

void bioWriteU16BE(BioFile *file, uint16_t u16);
void bioWriteS16BE(BioFile *file, int16_t s16);
void bioWriteU32BE(BioFile *file, uint32_t u32);
void bioWriteS32BE(BioFile *file, int32_t s32);
void bioWriteU64BE(BioFile *file, uint64_t u64);
void bioWriteS64BE(BioFile *file, int64_t s64);

uint16_t bioReadU16BE(BioFile *file);
int16_t bioReadS16BE(BioFile *file);
uint32_t bioReadU32BE(BioFile *file);
int32_t bioReadS32BE(BioFile *file);
uint64_t bioReadU64BE(BioFile *file);
int64_t bioReadS64BE(BioFile *file);

#ifdef __STDC_IEC_559__

void bioWriteF32LE(BioFile *file, float f32);
void bioWriteF64LE(BioFile *file, double f64);

float bioReadF32LE(BioFile *file);
double bioReadF64LE(BioFile *file);

void bioWriteF32BE(BioFile *file, float f32);
void bioWriteF64BE(BioFile *file, double f64);

float bioReadF32BE(BioFile *file);
double bioReadF64BE(BioFile *file);

#endif // __STDC_IEC_559__

#endif // BIO_H


My first library API.
>>
>>61626570
def palindrome?(str)
str2 = str.downcase.split.join
str2 == str2.reverse
end
>>
>>61626609
>supposed to be private but oh well
Why is it not though?
Why not just
typedef struct BioFile BioFile;
>>
File: ezgif-1-9b30574e8f.gif (4MB, 225x400px) Image search: [Google]
ezgif-1-9b30574e8f.gif
4MB, 225x400px
>>61625972
>electron
How come I just found out about this shit? I don't hang around hipsters, but it looks extremely good for small shit. I literally see no disadvantage if your shitty desktop app could have been a website except for local file handling. It's literally that: website + file system.

""""Redpill"""" me on electron, /g/.
>>
What do you guys think of my quicksort implementation?
void qsort(void* base, size_t num, size_t size, 
int (*compar)(const void*,const void*)){
size_t pivot = num - 1;
size_t i = 0;
while(i < pivot){
if(compar(base + i * size, base + pivot * size) > 0){
size_t j = size;
char tmp;
char *a = (char *)base + i * size;
char *b = (char *)base + pivot * size;
char *c = (char *)base + (--pivot) * size;
while(j--){
tmp = *a;
*a++ = *c;
*c++ = *b;
*b++ = tmp;
}
i--;
}
i++;
}
num = num - pivot;
if(pivot > 1) qsort(base, pivot, size, compar);
if(num > 1) qsort((base + pivot * size), num, size, compar);
return;
}


I also have a slightly shorter version for int arrays only.
void qsort(int *arr, size_t size){
size_t pivot = size-1;
size_t i = 0;
while(i < pivot){
if(arr[i] > arr[pivot]){
size_t j = pivot-1;
int tmp = arr[i];
arr[i] = arr[j];
arr[j] = arr[pivot];
arr[pivot] = tmp;
pivot = j;
i--;
}
i++;
}
size = size - pivot;
if(pivot > 1) quickSort(arr, pivot);
if(size > 1) quickSort(arr + pivot, size);
return;
}
>>
>>61626609
>supposed to be private
typedef struct BioFile BioFile;
Note that both the Linux kernel style guide and OpenBSD style(9) recommend against typedefing structs

You may want to have a method to bioOpen with a struct on the stack, rather than calling into malloc. In case it's used in embedded scenarios.

You're missing a seek function and file size retrieval function. Both are commonly needed.

Other than that, it works, I guess.
>>
>>61626632
What if someone needs it? Then I have to have a third file, called bio_private.h

Someone may need it if they for some reason will want to have custom initial-memory and memory-multiplication values for different files.

Also, I'll should I define NEW_FILE_MEM and MEM_MULTIPLIER in header or in source?
>>
>>61626668
I will load the whole file into memory. All operations are also going to be in memory. I never did anything embedded, this is for my game engine and custom model format.
>>
>>61626618
INEFFICIENT
do this instead:
def palindrome?(str)
str2 = str.split.join.downcase
str2 == str2.reverse
end
>>
How should I do a compile time initialization of an array that I want to use as a lookup table?
>>
>>61626609
I assume you're aware of fopen's "b" modes?
>>
>>61626725
Put in into a different source file with external linkage and use a some scripting language to generate it?
>>
>>61626741
I do know of them. I had initially thought about abstracting them with openForReading, openForWriting, openForAppending, but then I remembered about non-standard platform-dependent modes some people might care about.
>>
>>61626725
Use an enum as the keys to the table
Initialize the array with values in the same order as their associated enum elements
>>
File: portforwarding.gif (17KB, 711x535px) Image search: [Google]
portforwarding.gif
17KB, 711x535px
I have basic knowledge of networking.
Isn't port forwarding inherently secure? I mean, as long as no one is listening on a particular port, there's nothing that can happen, right?
>>
>>61626793
not programming
>>
I asked this in /fglt/, but no response so I'm trying with you bitches.

I'd like to add an item to the context menu in the GNOME file browser that opens the terminal in the current dir. I know I can do it with nautilus-action-config but I was wondering if I can do it with writing some own code. Do you guys know where I could add the code or should I just take it easy and do it with the nautilus stuff?
>>
>>61626650
change your pivot
>>
>>61626725
>compile time initialization of an array
what lang? Usually you don't need compile time initialization but just startup initialization.

If you need compile time initialization in C or something and if the lookup table is big enough, you're going to have to write a program that generates the source code for the static initialization. My strategy is to generally generate the data structure in lisp and replace the ()'s with {}'s and add commas in vim.
>>
>>61625683
>https://docs.python.org/3/library/unittest.html#unittest.TestCase.setUp

That works... Strange, cause the examples I was basing on didn't use it.
But it does seem more consistent.
>>
>>61626793
Inherently insecure. Script kiddies in china probe every port of random IPs.
>>
>>61627302
C++, I was hoping I could do some magic with constexpr.
>>
>>61627395
Oh yeah you can but constexpr is a jihad on compile time. Make sure to isolate your lookup table code in a separate .o file
>>
>>61626768
>>61626741
>>61626670
>>61626703
>>61626668
>>61626632
>>61626609


Shit, I realized I need to read about buffering if I want to avoid libc for maximum portability. Any quick reading recommendations? Should I look at how fopen, fclose, fseek, ftell, fread, fwrite is implemented in musl?
>>
>>61623683
fn palindrome(s: &str) -> bool {
s.chars()
.zip(s.chars().rev())
.all(|(a, b)| a == b)
}
>>
>>61626649
>it looks extremely good for small shit
And it turns it into extremely large shit in the process.
>>
>>61627435
That's what I'm trying. I can't seem to get it to work though.
The main issue I'm having is that the type of the array member has an empty default constructor, and constexpr doesn't like it because it leaves members uninitialized. I tried writing something like
constexpr std::array<MyClass, size> genLookupTable
{
std::array<MyClass, size> arr;
// init all members
return arr;
};
constexpr std::array<MyClass, size> lookup_table = genLookupTable();

And the compiler complained that it could not initialize arr.
>>
>>61627584
>An std::array lookup table where the return result is an object
?????????????

Anyway everything has to be marked constexpr including the constructor if I recall.
>>
Python or Ruby?
>>
>>61627708
That's my problem, I can't mark the default constructor as constexpr because I require elsewhere that I can construct a MyClass without initializing anything.
Whatever, I'll keep hacking away until I figure something out. Maybe I can use a variadic macro?
>>
>>61627869
python you rube
>>
>>61627932
Why do you need a lookup table? Lookup tables are usually optimizations.
Is initializing it in the beginning of your main procedure, init procedure, or whatever really off the table?
Why are you making an ""optimization"" that uses std::array? Fuck me anon just use a C array. You don't modify a lookup table.
>>
New thread:

>>61628058
>>61628058
>>61628058
>>
>>61628040
Doubt someone who doesn't know constexpr would sensibly complain about using memoization. Sure, you take a branch. But its way more convenient. And if he needed an actual lookup table it's easy to make one later. So what he should do is write a template that lets him automatically memoize calls.
>>
>>61625255
So what happens if you give it an empty string, or a null pointer? Does the function return a special value? How is it optimized with the knowledge that at least it's not empty or null?
>>
>>61625395
Isn't it pretty much just a promise that it won't receive a null pointer? Even '\0' works. And then, what optimization does it do with that knowledge?
Thread posts: 316
Thread images: 25


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.