/dpt/

daily programming thread: coffee shop edition

old thread almost dead, what are you working on?

Other urls found in this thread:

en.wikipedia.org/wiki/Johnson's_rule
youtube.com/watch?v=Wllc5gSc-N8
github.com/open-source-society/computer-science
twitter.com/NSFWRedditImage

...

Elma best dragon

...

...

...

...

So I am working with itextpdf and I have no fucking idea how to read the amount of "text" I can add to a rectangle, nor do I understand how to apply a new page incase the text overflows in the rectangle.

PLEASE KILL ME

>was interested in learning programming many years ago
>asked programmer friends what to learn
>Javascript is the easiest, but it's also a kiddie toy that will run slow as shit on every thing. You should man up and learn C or Assembly
>listen to them
>C was very hard, never even got to Assembly
>washed out of programming school

>now
>javascript is supreme
>i'm a NEET

nigger
nigger you hear me?
post a link to the old thread
post the link you nigger

I always wanted to do one of those. Rolling

rell

lol perfect

So I'm always told/reading that the biggest downside of c/c++ is memory management. But you use smart pointers for most things anyways, and even when you don't you just have to delete your pointer. Is there more to it? Do I not have enough experience?

yep, or you could just write a rudimentary memory manager in C, it's really hard and complicated for people to do malloc() and free()

please help me, if someone asked you to write between 300-500 LoC of C++ to show how much you know about the language and coding in general, what would you code?

preferably something that doesn't require months of research

well the best advice o can give is just use the stack as much as you can and let RAII do its business.

that way no need for smart pointer for everything.

just did number 4 in java. pls dont bully only pragramming for couple weeks now ;w;

But knowing C/C++ is gonna make learning almost any other language (javascript included) much, much easier. I would still recommend starting there.

void function1(int& num){ num += 1; }
void function2(int* num){ *num += 1;}

int main(int argc, char *argv[])
{
int number = 1;
function1(number);
function2(&number);
}


Are there any difference between these two functions other than syntax?

well, they accomplish the same but use different semantics.

one is by reference and the other is by pointer.
the big difference is the old pointer vs reference.

pointers are values, passed by values and have their own addresses.

where references are like "aliases" to variables, they share the same address, if you print the address of "number" and the address of "num" inside the function you will see that its the same.

#include
#include
#include
typedef unsigned int uint_t;
typedef struct Error { char *type; char *msg; int id; } Error;
#define API_ERROR ((Error) {"API ERROR", "An API Error has occured", 1})
#define ABI_ERROR ((Error) {"ABI ERROR", "An ABI Error has occured", 2})
#define LIB_ERROR ((Error) {"LIB ERROR", "A Library Error has occured", 3})


void throw( Error e, uint_t callLine )
{
char *syscall;
asprintf(&syscall, "sed -n %d,%dp %s", callLine-5, callLine+5, __FILE__);
printf("(%s) - {%s [ID:%d]} :: invoked at line |%d|\n", e.type, e.msg, e.id, callLine);
system(syscall);
exit(EXIT_FAILURE);
}

int main(void)
{
throw(LIB_ERROR, __LINE__); return 0;
}

what os and other things are you using here

does the pointer in function2 automatically get deleted? I tried
void function2(int* num){ *num += 1; delete num;}

and the value of number in main was still 3. Did delete just make it so the address of number in main could be overwritten potentially allowing corrupt data?

you only have to delete pointers that you allocated with new (or any other allocator like malloc())

in your case, you do not delete the pointer, since it wasn't allocated in the heap (with new or malloc), so no need to delete it. just return and variable itself will be destroyed on scope end

>2017
>using raw pointers.

os: windows 7
ide: jgrasp

Where'd you get the idea anything had to be deleted?
Nothing should ever be deleted in C++ if it's not come out of a "new" expression, and nowhere is implicit delete to be found. Besides, it's dynamically allocated memory that needs to be new'd and deleted, not the pointers that point to it per se.

very nice love the look

oops

Lost as fuck in how to implement Johnson's rule in java. Can Sup Forums help me?
en.wikipedia.org/wiki/Johnson's_rule

Have your read your SICP today?

Number 37 palindrome checker in (((Python)))

rolling

Are you sure it's Python? It looks like Lisp.

rolling

how should I structure a gui application with a procedural language like C ?

TCL/TK

Like in any other language.
You start your window and add components to it. Then you add events on your components.
Inheritance is not needed.

but where should I put the state?

In some struct that you pass around the functions.

i really like this thread

Latest version here

fuck you

Did you have a stroke or something?

yes please

need help:

UnicodeEncodeError: 'ascii' codec can't encode character u'\xae' in position 47: ordinal not in range(128)

reading from sqlite db.

Have tried:
row[1].encode(sys.getdefaultencoding())

This doesn't look like any SQLite library I've ever seen.

The number of if else statements made me cry.

look up what a hashmap is

...

raphin

Writing an optimizing C compiler in pure lambda calculus (with pen and paper).

>(with pen and paper).
cheater

can we make the next thread for people who work at home or out of an office because they are employed

Is compilation time directly proportional to the number of lines of code in your project?

it's directly proportional to the amount of abstraction you give it. More functions? More resolving, inlining, etc. More templates? More generation.

Now wrap it in a (disgusting) macro (because C lacks proper macros) so that you can omit the __LINE__ when you call throw.

Also
>syscall sed
lol

Just rename throw to _throw, then make a macro like
#define THROW(x) _throw(x, __LINE__)


then you can just do THROW(LIB_ERROR) instead of having to type out __LINE__ each time

is_palindrome = lambda x: x == x[::-1]

>More templates?
Sorry, I'm not subhuman.

97

print(142913828922)

Roll.
The difficulty sure varies though, from "add two numbers" to "rewrite the .NET framework"

I feel ya, had to work with itext before and it's bollocks. The library author, Bruno lowagie or whatever, is an utter cunt to work with. He's the primary poster for itext questions on stack overflow and every time he replies there's always an autistic, Sup Forums-esque aura of "why can't you use my steaming piece of shit?"

The other dpt seems to have contained the autists for now

Well done, user. Well done

>a compiler with no I/O
sure makes sense

fuck calculus

All languages are inferior to Haskell, if you don't believe me just listen to me scream for as long as I can

Threads dead baby, threads dead

Is there a better way to write a hex editor for big files than using span-tables?

Tfw entire thread is people stumbling over the idiosyncrasies of low level babby shit instead of actually making something useful.

everytim

Roll

So what would you suggest, since you're clearly hackerman, king of the autists

Wrong. That's the sum of all prime numbers, not square numbers.


>>> def testSquare(num):
... if (num**0.5)%1==0:
... return True
... else:
... return False
>>> counter = 0
>>> for i in range(0, 2000001):
... if testSquare(i):
... counter += i
...
>>> counter
943381915
>>>

This has O(n) complexity, but to make it O(1) just print the result like you did before.

can someone help me with this batch script im trying to make (i have zero experience with this)

i want to rename every file in a particular folder to a name starting with '148' and then 10 random numbers, (a Sup Forums filename)

this is to randomize all Sup Forums saved images/webms etc within a particular folder

@echo off
setlocal disableDelayedExpansion
set "chars=0123456789"
for /f "eol=: delims=" %%F in ('dir /b /a-d *.txt') do call :renameFile "%%F"
exit /b

:renameFile
setlocal enableDelayedExpansion
:retry
set "name="
for /l %%N in (1 1 10) do (
set /a I=!random!%%10
for %%I in (!I!) do set "name=!name!!chars:~%%I,1!"
)
echo if exist !name!%~x1 goto :retry
endlocal & ren %1 %name%%~x1


i got this so far which gives me random 10 number file names but for txt files only
how do I get it to work for all file extensions (png jpg webm) and have 148 or 149 etc in front of the random 10 numbers

youtube.com/watch?v=Wllc5gSc-N8

webdev

Gill Goldschein

>So what would you suggest
Something more entertaining than endless questions about pointers and how to write fizzbuzz-tier crap. But that will never happen because there are too many pajeets here. I hope you all enjoy wasting away while thinking you accomplished something today.

>/daily boring as hell thread/

So why don't you share what you've been doing? If anything I'm sure it's just some dumb JS project. That shit is boring as hell.

> Thinks he's above programming challenges
>Can't give concrete suggestion, replies with nebulous horseshit about more entertaining challenges

Yeah, /dpt/ won't miss your absence. Go back to watching your wife get fucked by some college kid

Nevermind, i figured it out

@echo off
setlocal disableDelayedExpansion
set "chars=0123456789"
for /f "eol=: delims=" %%F in ('dir /b /a-d *.png *.jpg *.webm') do call :renameFile "%%F"
exit /b

:renameFile
setlocal enableDelayedExpansion
:retry
set "name=148"
for /l %%N in (1 1 10) do (
set /a I=!random!%%10
for %%I in (!I!) do set "name=!name!!chars:~%%I,1!"
)
echo if exist !name!%~x1 goto :retry
endlocal & ren %1 %name%%~x1

Any flat file database alternatives to SQLite?
The C API is on one hand really well documented, on one hand some critical parts lack any documentation whatsoever giving you just the function signature.
And some things sometimes silently fail because no error code gets set.

What do you think of my solution for a variable that can be set once during runtime and then can not be changed?

//WPV: Write Protected Value
template
class WPV
{
WPV(const WPV &other) = delete;
WPV(const WPV &&other) = delete;
public:
WPV() {}

void Set(T v)
{
static T buf(v);
val = buf;
}
T Get()
{
return val;
}
private:
T val;
};

Who are you replying to?

>No one
> No matter how much you spam the quoting bollocks, this will happen in just about every board
> Quotefags on suicide watch

Why not just:
template
class WPV
{
WPV(const WPV &other) = delete;
WPV(const WPV &&other) = delete;

T value{};
bool set = false;

public:
WPV &operator =(const T &value)
{
if (!set) {
this->value = value;
set = true;
}

return *this;
}
};

And so on?

I finished cs50 on EDX, which other course is a good follow up/complementary? I wish there was a curriculum using all these online classes, there are so many nowadays.

this video though...

how do you deal with your chronic back pain, /dpt/?

> Quotefags on suicide watch
I think not. I actually think they get a perverse sexual pleasure from this.

by sitting like this

The if(!set) is uglier. But you're right, i forgot to deal with the assignment operator.

I guess this might do.
github.com/open-source-society/computer-science

I'm still accepting suggestions.

Yeah you're probably right. Still though, it's good for the odd yuck to troll these faggots

>So why don't you share what you've been doing
>Can't give concrete suggestion
Because 95% of people who frequent these threads are actual NEETs that can't even grasp the basics of computer science. Majority of posters will never give a shit about anything that deviates from the "roll for a shit programming challenge" norm.

>Majority of posters will never give a shit about anything that deviates from the "roll for a shit programming challenge" norm
I'd estimate that population to constitute a little under 50% of the thread

>Write a “CntBits” function that counts the number of one bits in a 16-bit integer value. Do
not use any built-in functions in your language’s library to count these bits for you.

does this mean i'm not allowed to use something like a while loop? i'm planning on doing for i in range (16), if(x & 1) count += 1, and then x >>= 1

do you think that's cheating or acceptable by that question wording?