/dpt/ - Daily Programming Thread

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

Other urls found in this thread:

strawpoll.me/14754710
kernel.org/doc/html/v4.10/process/coding-style.html#placing-braces-and-spaces
twitter.com/NSFWRedditGif

first for very important issues
strawpoll.me/14754710
strawpoll.me/14754710
strawpoll.me/14754710

Reverse probabilistic 2D regex. It generates 2D patterns instead of matching strings.

JavaScript is the greatest language

How can I deploy my C++ projects?
I use Maven for Java, but I don't know what to use for C++..

K&R all the way.

kernel.org/doc/html/v4.10/process/coding-style.html#placing-braces-and-spaces

making a preference bundle (settings page) for my tweak, just updating the .plist file now (i've stripped this down for simplicity):


items


cell
PSButtonCell
label
Enable
action
enable


cell
PSButtonCell
label
Disable
action
disable


title
RemoveDock

iToddlers...

Does anyone use visual studio here?
I never hear anything about it. Is it not good or something?

B L O A T
L
O
A
T

What IDE do you use for C++?

I'd assume it's because of the use of Linux. Also, I personally hate it because of how bloated and slow it is to get up and running.

Daily reminder that all languages compile to an IR regardless of their interpreted (VM)/native (no VM) execution model, regardless of their association with LLVM

Orwell Dev-C++
Code::Blocks
GCC + command line

>inb4 machine code is actually IR because muh microinstructions

Emacs with company and flycheck

Reminder that C and C++ are interpreted by the big two compilers

it's not

>inb4 constructing an AST is "interpretation"

>clion student edition is only for non-commercial projects
how could they prove you used it in a commercial project?

emacs

>how could they prove you used it in a commercial project?
They couldn't, but if you're big enough to matter, you probably employ quite a few people, not all of which can be trusted to keep your illegal activities secret forever, and you have enough money to pay for a license anyway.

What's Eclipse like for C++, or just in general?

I use it, it's ok. The only reason I do though is for .NET languages.

Learning the ropes of using Haskell
I'm having a bit of trouble implementing mergeSort, though.
My "halve" and "merge" functions work, so I'm not really sure where my problem is. Any hints? or at least how to debug in Haskell?

myHalve :: Eq a => [a]-> ([a],[a])
myHalve list
| (list == []) = ([], [])
| otherwise = (take halflen list, drop halflen list)
where halflen = (length list) `div` 2

merge [] list2 = list2
merge list1 [] = list1
merge (l1:list1) (l2 : list2)
| (l1 > l2) = l2 : merge (l1:list1) list2
| otherwise = l1 : merge list1 (l2:list2)

{-
Now define the function mergeSort :: Ord a=> [a]->[a],
where any list is sorted by mergint the two lists that result from
sorting the two halves of the list separately
-}

--Cases with zero and one element
mergeSort [] = []
mergeSort [x]= [x]

--General case of MergeSort
mergeSort (x:xs) = merge lHalf' rHalf'
where (lHalf, rHalf) = myHalve (x:xs)
lHalf' = mergeSort lHalf
rHalf' = mergeSort rHalf

>Learning the ropes of using Haskell
srlsy? haskell? what's the point of using haskell over C, C++ or C#?

shit

more expressive code

It's a high level language that, unlike python, actually feels like thought was put into its constructs. There's a definitive ideology behind it that isn't "just put shit together until it sort of works" and it's surprisingly easy to translate between English and Haskell if you know what you're doing

Writing a four line quicksort function is really flipping cool
quickSort (elem: list) = smaller ++ [elem] ++ larger
where smaller = [x | x

*Main> [6..1]
[]

When comments are not enoght, so you have to invent whole new langluage.

Oh shit, really? Huh. Though the list shorthand syntax could work the other way around.
God dang it.

>trusting the comments over the code
You're a bad programmer.

I've seen this sort of shit in other people's code:
it+=it; // this increments it

>implying it doesn't increment `it`
The comment doesn't say it increments `it` by 1, does it?

Sublime 3 + CMake + Clang

offside/lisp obviously

a very abstract framework for finding an initial peer to bootstrap from (and later use that for a
p2p network that can be run anywhere)

Bad. Eclipse kinda blows in general.

fuck Objective-C
why am I doing this to myself

Why is visual studio whining that identifiers for pow and sqrt can't be found when #include and #include are both at the top?
What the fuck is going on?

Yep, I fuckup'd the example, but you get the idea

c++ is the greatest language of all time

namespaces

using namespace std

>what's the point
Adding one more string to your bow. How can you use the best tool for the job if you only ever used one tool in your entire life ?
C, C++, C# totally overlap each other.

if you build (f7) and it succeeds but you're still getting the error, then it just means intellisense has crashed
happens to me all the time. gotta restart VS

...

Turns out it's because #include "stdafx.h" wasn't first.

the absolute state of windows programming

I have a question for /dpt/ since you are the most intelligent thread on this board
I have a Sandy Bridge i5 processor from many years ago and will this Intel 30% thing affect me and if it does can I sue Intel for selling me a defect product that is not what they advertised ?
Thank you

I have work due in 1 week for an assignment where I have to create a basic program in C. My lecturer is Asian and nobody can understand a thing he says, despite apparently graduating from Harvard. Is there anyone I could pay?

Just post what you have till now
I'll help

This sounds like a pretty basic and doable thing.

If this were in advent of code it would have been solved in under 30 seconds

That's pretty easy though, within 1 week you could teach yourself enough to make that program even if you had no prior programming knowledge whatsoever.
You should really try to do it yourself, throwing in the towel this early on is going to fuck you over big time later on

Could you please try to compile this on any C++ program you use? It works on cpp.shell but DevC++ wont output result. It should sort elements in array from lowest to highest or maybe other way

#include
using namespace std;

int maxValue(int b, int a[]) {

int max = a[0];
for (int i=0;i=max) {
max = a[i];
}
}
return max;
}
int maxValueIndex(int b, int a[]) {
int maxIndx;
int max = a[0];
for (int i=0;i=max) {
max = a[i];
maxIndx=i;
}
}
return maxIndx;
}

int minValue(int b, int a[]) {

int min = a[0];
for (int i=0;i

Post what you have till now

(he has nothing)

What the fuck are you doing in a course that teaches you C if you have no interest in it?

CMake

Jenkins

I don't know much about c++, but doesn't n have to be constant ? you're creating your arrays on the stack, right ?

That's correct. While C99 allows variable length arrays, C++ does not.
Although g++ and clang++ provide this functionality as an extension.

>the most intelligent thread on this board
kek

Lel
Except your function sucks and does not sort correctly
Protip actually use recursion in a recursive definition.
And plz post a corrected version

It's a Computer Networking course and covers a range of topics, with some irrelevant ones such as "writing and research in the workplace" that is nothing more than reading a paragraph then paraphrasing what was said.

I can't copy/paste using the website that I have to submit using as it's disabled due to using a "secure" browser

jesus c++ is hard

here you go

#include
using namespace std;

int maxValue(int b, vector a) {

int max = a[0];
for (int i = 0; i= max) {
max = a[i];
}
}
return max;
}
int maxValueIndex(int b, int a[]) {
int maxIndx;
int max = a[0];
for (int i = 0; i= max) {
max = a[i];
maxIndx = i;
}
}
return maxIndx;
}

int minValue(int b, vector a) {

int min = a[0];
for (int i = 0; i

maybe computers aren't for you, user

oh , also put #include at the top

int * tab = new int[n];

/* ... */

int* tabRosnac = new int[n];

1TBS, but voted K&R because it's close and way better than Allman.

That program is much more about basic logical thinking and problem solving than any kind of programming prowess, so it being part of a more general course makes sense.
You should definitely work on it yourself, you have an entire week after all. It's really not asking all that much, just take it one step at a time.

Maybe you're misunderstanding, I can only access the website using a browser they provide, and copy/pasting is disabled along with many other features to prevent cheating

How does /dpt/ structure its program?
Do you split your code between domains? Do you use a meme pattern like MVVM or MVP? Or do you write spaghetti code?

>Writing a four line quicksort function is really flipping cool
You can write a "four line quicksort" like that in any language that supports recursion and has a list structure in the standard library, but all of these toy implementations are useless with shit performance. A proper quicksort in Haskell looks worse than C.

Why would you work on the project in some shitty web frontend?
Download an IDE and fuck around with it on there. You have the instructions already, what more do you need?

You're a bit slow aren't you? Are you really sure working with computers is what you want to do once you are all grown up?

int size = sizeof(ar) / sizeof(ar[0]);
How does this work? How does it give the size of the array?

let's get started. decide how you want to store the current state of a player—one idea would be to have an array int cards[10] and a counter int n that keeps track of how many cards are actually there
task #1 is to read that two-line input and get it into these variables

how would you exploit the intel fuckup?

I know I know, the only reason I did so was because my lecturer advised that we did so in order to ensure compatibility

size of an array / size of a single element = number of elements in the array
How is this hard to understand?

ar is an array of things of size n (thing[n])
ar[0] is a thing
ergo sizeof(ar) = sizeof(thing[n]) = sizeof(thing) * n
and sizeof(ar[0]) = sizeof(thing)
thus size = sizeof(thing) * n / sizeof(thing) = n QED
Obviously not gonna work if ar is a pointer and not an array in compile-time terms.

anyone happen to have some JS to block the add on the bottom of the page on Sup Forums?

adblock + adblock pro + ublock

how do i declare an array in c++ using a variable to set its size?
i.e.
int ar[val];
it won't allow it.
i want a function to take an array as a parameter and return another one.

ayyyyyyy you guys took down the Pentagon yet

Thanks, "Ublock" did it for me

You don't if you want to be standard compliant - although g++ and clang++ allow it.
The easiest way to get this behavior portably is to use a vector.
#include

...

std::vector vec;
vec.resize(val);

Obviously you can't, you have to allocate memory..

int *arr = new int[size];

remember to delete it.

For what you want to do, you should probably use std::vector though.

int n;
cin >> n;

vector arr;
arr.resize(n);


vector MyFunc(vector param){
vector ret;
return ret;
}

by short selling

Javascript is a high level language that, unlike Haskell, actually feels like thought was put into its constructs. There's a definitive ideology behind it that isn't "just put shit together until it sort of works" and it's surprisingly easy to translate between English and Javascript if you know what you're doing

Writing a five line quicksort function is really flipping cool
function qsort(arr) {
if(arr.length < 1) return arr;
var left = [], right = [];

for(var i = 1; i < arr.length; ++i)
(arr[i] < arr[0] ? left : right).push(arr[i]);

return qsort(left).concat(arr[0], qsort(right));
}

Note that this one works, unlike its Haskell counterpart, and doesn't perform quite as badly.

nice, still wont output in dev c++
const int

struct Player{
int cardCount;
int* cards;
};

int getMin(int a, int b){
//return the lower value of the two integers a and b
}

void sort(int* numbers){
//sort the array from greatest to lowest value
}

int main(){
Player player1;
Player player2;

//get input, check if between 2 and 10
player1.cardCount = input;
//get input, check if numbers match cardCount
//check if numbers between 1 and 10
player1.cards = malloc(player1.cardCount*sizeOf(int));
//Assign numbers to player1.cards
sort(player1.cards);

//Repeat above for player2

for(int i=0; i < getMin(player1.cardCount, player2.cardCount){
if(player1.cards[i] > player2.cards[i]){
//output player1 wins
return 0;
} else if(player1.cards[i] < player2.cards[i]){
//output player2 wins
return 0;
} else {
//output draw
return 0;
}
}

if(player1.cardCount > player2.cardCount){
//output player1 wins
return 0;
} else if(player1.cardCount < player2.cardCount){
//output player2 wins
return 0;
} else {
//ouput draw
return 0;
}
}

>nice, still wont output in dev c++
probably because dev c++ is ancient
get visual studio

Hell no mate. JS is a not a good example for that claim. It's an awful abortion of a dynamic, scheme-like language that was casted into those shitty C-like syntaxic traits for no practical reason, and it's shit all around.

get Orwell instead

Does helloworld actually output anything on "dev c++" according to you? sure it's not you being unable to use this IDE properly?