/dpt/ Daily Programming thread

This is /dpt/, the best subreddit of Sup Forums

In this thread:
r/programming
r/compsci
r/ReverseEngineering
r/softwaredevelopment

/!\ ** Read this before asking questions ** /!\

mattgemmell.com/what-have-you-tried/
catb.org/~esr/faqs/smart-questions.html


What are you working on?

Other urls found in this thread:

raw.githubusercontent.com/chapel-lang/chapel/release/1.16/CHANGES.md
users.rust-lang.org/t/why-is-rustfmt-crashing-at-all/3189/2
open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf
wiki.c2.com/?MemoryLeakUsingGarbageCollection
doc.rust-lang.org/std/vec/struct.Vec.html
twitter.com/SFWRedditGifs

>/!\ A L E R T /!\
>not \a

Any tips on learning how to do proper text parsing? I'm doing a simple converter between two languages. Regex seems way too slow and I'm just iterating over the text character by character with a stack for tokens. Can it be done better(i.e. faster)?

>you can't reduce O(1)
Unicode character lookup is not O(1).

fuck opengl, though

C++ and C are equally shit

>trying to learn reverse engineering

Who chapel 1.16 here?raw.githubusercontent.com/chapel-lang/chapel/release/1.16/CHANGES.md

i rate your github/bitbucket/gitlab/whatever on 10.

of course it is

>Can it be done better(i.e. faster)?
Of course it can, just use LISP ;^)

OK. lets talk about why people dont understand indexing. example in rust and C.

Rust
let pangram: &'static str = "the quick brown fox jumps over the lazy dog"; // O(1) alloc
for word in pangram.split_whitespace().rev() { // O(1) indexing - stores size
println!("> {}", word);
}

safe and.
now C
while(*a != 0) // thanks to user for helping 1 O
{
// For each new char you have to do 4 O's. therefore O(n^2)
char b = *a; // 1 Operation (ill call it an O)
b++; // second O
*(a + 1) = b; // Third O
// You want to reverse string?
if(!(a - 1)) return;
*(a - 1) = b - 1;
++a;
}


see difference?

>For each new char you have to do 4 O's
wat

Do you use a lexer generator? It works by building a nondeterministic finite automaton representing your tokenization logic, then does a powerset construction, and finally state minimization. Flex, for example, emits C code, which you could trivially convert to another language. This gives you a lot of flexibility in your lexer design while also allowing to be performant.
Once you have your tokens, I recommend CYK.

Get paid X to develop in a language you enjoy or 2X to develop in a language you hate?

>reading old book
>go to www.shit.com to learn more about this
>page doesn't exist

i am proving to anons from previous thread that C cannot do O(1) lookup. they do not understand how null termination works and the massive overhead it has.

i am yet to cover signedness. they don't get that either.

is this post troll or autism?

>what is sds
>what is bstring

That's not an O, that's a 0

what language are you learning? I suggest stay away from C (and family) due to terrible optimizations + horrible performance.
see signedness
int a = 0;
a = -13234; // should fail to compile as on MSVC but GCC/Clang allow it to pass, both incorrect compilers.

worthless junk; why?

>third-party libraries

no see i am helping them understand why null termination is horrible and slow and ugly.
rust stores size which allows it to access memory at O(1) + indexing is also O(1) unlike C.

Why is it invalid?

Why are these rust shills so fucking retarded?

why are you?

why o(n^2)? strlen is o(n), after that, you know the size of the string.

What are you reading?

How are you at these:

- OS internals
- IA-32, x86_64, and/or ARM assembly
- Executable formats: PE, ELF, Mach-O
- Calling Conventions
- Using a debugger (which one?)
- Using a disassembler (which one?)
- C and C++ and the code they emit
- Using Python
- TCP/IP
- HTTP
- using a hex editor
- file system details

Depending on what you want to do, the networking stuff might not be needed. Lots of RE tools use Python, but beyond that it’s not strictly necessary.

Lastly: how do you feel about staring at hexdumps and disassembly dumps for hours and hours and hours at a time?

Standard says so. See the C Standard.
Show me where I was wrong. Anywhere and I shall concede.
In rust you have u32 which is unsigned explicitly.
In C you have int. this is NOT SIGNED NEITHER UNSIGNED. it is simply an int.
in order to make in unsigned or signed you have to do
int test = 4; // Regular Int if you do
test = -1222; // Compile error but this
signed int test_sign = -1212324234; // Works

Always activate your almonds before you post, kids.

Only with an encoding that's an array of pointers to big integers can you have O(1) Unicode character lookup. C strings can't even handle UTF-8 fully because of null so they definitely can't do that.

Is there a way to stop cache building in Visual Studio 2017?
I'm writing a lot of small programs in C++ which originally are around 300KB in size, but once the cache is built the project size grows to 200MB. What the hell?
I'm syncing these projects with the cloud, so the smaller the project the better. I can manually delete these bloat files, but they're rebuilt every time the VS starts and it's a pain to do that for every single small project.

Rust has all of these. DO NOT USE C for ENGINEERING..
C is horrible. all modern engineers use Rust.

So this is what mental illness looks like.

yes. use rust. improved caching and no C++ nonsense. also it has full modules and proved signedness.
not to mention it is built to be a full functional programming language unlike C.

Rust is safer and generally better to use, and in terms of programming safety C is indeed horrible and hard to write in, but it seems like you're confusing yourself between lookup/checking and access. There are situations in the programming world where you don't have to "look up" or "confirm" the size of something. You know the size beforehand and therefore you don't need that information. Period.

For 90% of modern intents and purposes you aren't wrong, but for pushing the limits of optimization of pre-defined operations you're barking up the wrong tree.

rustfags are too dumb to read standard or progam in C which is one of the simplest languages to program. How could anybody take them seriously?

You didn't prove me wrong. Show me where I am wrong. MSVC will rightfully reject this as an error (since it is one). GCC is false don't use it.. wasn't approved by the C standards.

>you gotta prove me wrong every time i make a retarded claim
Take your pills next time.

Exactly. C lookup is atrocious. C barely has any proper modern coding conventions. Plus functions are implemented awfully too. Headers/Impl? YUCK!.

>What are you working on?
Adapting ffmpeg's thumbnail filter for a Go thumbnailing library.

This is an ad hominem. You just proved me correct. C has no proper signedness unlike Rust. Also null termination.

Are you one of those memelords who believe in pictures like this?

>C gives you more control than C++
nice meem

Mozilla is the reason rust and js exists. Maybe it would be for the best if Mozilla stopped existing.

just ask

DO NOT USE C OR GO.
both languages are atrocious and you are literally wasting performance. if you dont check your bounds once you get an underflow issue.

The C Programming Language is almost 50 (FIVE ZERO) years old!

>you just proved me correct by pointing out that i'm just spewing unsubstantiated assertions
Take your pills, kid.

this is correct. you cannot crash a Rust program its impossible. it has compile time Garbage Collection and bounds checking. unlike C.
ask what?

>he's never used a negative integer as an array index

arrays are not pointers

POSTING IN SHILL FILLED THREAD

>you cannot crash a Rust program its impossible.
users.rust-lang.org/t/why-is-rustfmt-crashing-at-all/3189/2

What does having an integer that is neither signed nor unsigned even mean? Could you link the relevant part from the C definition?

C has no proper signedness.
compile and watch this crash
int main()
{
int a = 0; // NORMAL INT
char* test = a; // Allocate on stack as pointer
if(test != 0) return 1; // Works
test = -1;
*test = 1; // Set memory cell at int location to true and CRASH. proof it isnt signed
return 0;
}

contrary this works
int main()
{
signed int a = 0; // NORMAL INT
signed char* test = a; // Allocate on stack as pointer
if(test != 0) return 1; // Works
test = malloc(256);
*test = 1; // Set memory cell at int location to true and WORKS. its signed
return 0;
}

Any way to negate elements (multiply with -1) of an array with a specific probability in python?

e.g. (pseudocode)

foreach elem in arr
if(random.random < epsilon)
elem = elem * -1

Please port ffmpeg to Rust. I'll come back tomorrow, when you're done.

you are dereferencing address -1 you fucking retard

Don't you have anything better to do than pretend you're a Rust shill while posting complete bullshit? Rust crashes if you do something wrong that it can't statically check because it's better than going ahead and exposing a vulnerability through a memory error.

Rust gives you more control by invalidating any algorithms its primitive borrow checker can not comprehend.

Too many rust shills

C Standard open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf
6.3.1.3 Signed and unsigned integers
1
When a value with integer type is converted to another integer type other than
_Bool
,if
the value can be represented by the new type, it is unchanged.
2
Otherwise, if the new type is unsigned, the value is converted by repeatedly adding or
subtracting one more than the maximum value that can be represented in the new type
until the value is in the range of the new type.
60)
3
Otherwise, the new type is signed and the value cannot be represented in it; either the
result is implementation-defined or an implementation-defined signal is raised.

requires explicit signedness.

Or even better something like this: (python pseudo code with ternary operator)

arr * (numpy.random.uniform(len(arr))

Like so?
from random import randint

INTERVAL = [1, 10]
EPSILON = 5

def cb(v):
if randint(*INTERVAL)

>rust literally prevents you from writing unsafe code because the compiler crashes when you attempt to write unsafe code

Where would we be without mozilla's good graces?

It is impossible to have a memory leak in a garbage collected language

then why does the explicitly signed example work?

If an allocation is reachable but never used, it's considered a memory leak.

wow
female programmer
so smart
much code

>there’s a troubling secret about Rust
>it’s said the name comes from a sort of fungus, but this isn’t true
>the homosexual community has long used Rust in various slang, to give two examples:
>”the rusty trombone”
>”the rusty sherriff’s badge”
>the first refers to the acting of performing analingus while simultaneously manually manipulating the penis
>the second refers directly to the anal sphincter itself
>this is a subtle message, but it conveys a great truth:
>Rust is shit.

exactly.
write it in rust. python is too slow.
in python (O(n^5))
from random import randint

INTERVAL = [1, 10]
EPSILON = 5

def cb(v):
if randint(*INTERVAL)

not really.

No, a memory leak is unreachable allocated memory.
I bet you're one of those autists that frees the window context and everything in it before closing the program, like who fucking cares, you're just gonna give the memory back to the OS anyway.

He asked about Python though. Did Mozilla tell you to forget about reading comprehension skills?

RUST CANNOT LEAK SINCE ITS GC AT COMPILE TIME.
ALL MEMORY IS REACHABLE BUT RUST CATCHES IT AT COMPILE

wiki.c2.com/?MemoryLeakUsingGarbageCollection

Yeah, thanks

How do you write a doubly linked list in rust without using the unsafe pointer? Genuine curiosity. I'm new to rust.

Luckily rust already has this since its standard library is way better than C/C++!
doc.rust-lang.org/std/vec/struct.Vec.html
Here! Hope this helps. Yaaaas queen

i don't care and will not read. memory leak is when the memory is lost.

eg:
c = malloc(...);
c = null; // memory is lost for ever.

If the programmer thinks the memory has been freed but it's still reachable (so the GC won't free it), it's the same shit with a different smell.

>all this desperate rust shilling
I bet they are americans, there's no such thing during european hours

>vec.rs
>^F unsafe
>58 results
hmmm

but it isn't though.
c = malloc(...);
c = null;
while(1)
{
c++ = 1; // if doesnt crash you found your lost memory!
}

let mut vec = Vec::new();
vec.push(1);
vec.push(2);

assert_eq!(vec.len(), 2);
assert_eq!(vec[0], 1);

assert_eq!(vec.pop(), Some(2));
assert_eq!(vec.len(), 1);

vec[0] = 7;
assert_eq!(vec[0], 7);

vec.extend([1, 2, 3].iter().cloned());

for x in &vec {
println!("{}", x);
}
assert_eq!(vec, [7, 1, 2, 3]);


It's pretty amazing that people actually pretend to enjoy working with this trash.

it's bad gestion, not a leak.

If it's reachable and you're too lazy to free it that's your problem.
Wasting memory is NOT a memory leak.
Memory leaks may waste memory, but wasting memory doesn't HAVE to be a memory leak.

>c++ = 1;
Mark Wahlberg confused gif

that's infinite loop doing nothing you retard.

no you are checking if memory is accesseble by you. if it isnt the OS will crash you. if it doesnt crash you found your 'leaked' memory!
its iterating through all possible addresses on 64bit OS.

Do you really have to constantly assert things you know?
Imagine justifying your program's existence to your compiler, 1.6x10^9 times a second.

NO! this is safe unlike trasC or Shittel or even Lisp (only for Birignf)

I imagine you don't, but it's just to prove correctness.
Even Rust's asserts are gross.

...

I fail to see how the part you linked supports your claim, as in the case you detailed the first case is true (the negative value can be represented by the type int), and the value is left unchanged. Also clearly every integer is either signed or unsigned.

From chapter 6.2.5 Types:
>There are five standard signed integer types, designated as signed char, short int, int, long int, and long long int.
Note the plain old int, which is a signed type

From chapter 6.2.6.2 Integer types:
>For signed integer types, the bits of the object representation shall be divided into three groups: value bits, padding bits, and the sign bit. There need not be any padding bits; signed char shall not have any padding bits. There shall be exactly one sign bit. Each bit that is a value bit shall have the same value as the same bit in the object
representation of the corresponding unsigned type (if there are M value bits in the signed type and N in the unsigned type, then M ≤ N ). If the sign bit is zero, it shall not affect the resulting value. If the sign bit is one, the value shall be modified in one of the following ways:
>— the corresponding value with sign bit 0 is negated (sign and magnitude);
>— the sign bit has the value −(2 M ) (two’s complement);
>— the sign bit has the value −(2 M − 1) (ones’ complement).
>Which of these applies is implementation-defined, as is whether the value with sign bit 1 and all value bits zero (for the first two), or with sign bit and all value bits 1 (for ones’ complement), is a trap representation or a normal value. In the case of sign and magnitude and ones’ complement, if this representation is a normal value it is called a negative zero.

I hope the formatting doesn't break too much.

BYE BASIC!!!

M I L K Y
O
M
M
Y

no. int is neither signed nor unsigned. your quote proves this. it says
> There are five standard
STANDARD. only the signed are signed.