/dpt/ - Daily Programming Thread

Joshua Davis
Joshua Davis

What are you working on, Jow Forums?

Last thread: jowforums.com/thread/70581127/technology

Attached: 1486600538102.png (619 KB, 1280x720)

Other urls found in this thread:

github.com/Cloudnaut/AID
jowforums.com/thread/70581127/technology
en.cppreference.com/w/cpp/memory/gc/declare_reachable
devdocs.io/javascript/statements/for...of
smtebooks.com/
en.wikibooks.org/wiki/C_Programming/Structure_and_style
learn-c.org/en/Hello,_World!
doc.rust-lang.org/1.5.0/std/macro.write!.html
vssut.ac.in/lecture_notes/lecture1424354156.pdf
amazon.com/VivoBook-Portable-i5-8250U-processor-S510UA-DS51/dp/B078YMY5VZ/ref=sr_1_19?keywords=laptop&qid=1555535241&refinements=p_89:Asus&rnid=2528832011&s=gateway&sr=8-19
amazon.com/Flagship-Processor-Celeron-soldered-Bluetooth/dp/B07NJ6CPZR/ref=sr_1_16?keywords=laptop&qid=1555538694&refinements=p_89:Asus&rnid=2528832011&s=gateway&sr=8-16
zedshaw.com/2017/08/26/what-if-it-worked/
github.com/kw-udon/constexpr-8cc
dev.stephendiehl.com/hask/#monadic-myths
jowforums.com/thread/70595085/technology
jowforums.com/thread/70596661/technology

Thomas Roberts
Thomas Roberts

cleaning up a shit iso-14229 implementation at work

Attached: 1552127653035.jpg (72 KB, 508x592)

Logan Rodriguez
Logan Rodriguez

wish I could sleep forever

Attached: 1461926165210.gif (361 KB, 400x225)

Henry Ramirez
Henry Ramirez

JavaScript? That sounds nice!

Attached: 4d24ff4e6797a37ed79c564579e294c4.jpg (56 KB, 564x957)

Andrew Davis
Andrew Davis

What are some neat projects that I could make as a portfolio?

Kayden Davis
Kayden Davis

I WANT TO ăȘかだし KAREN!!!

Kevin Bell
Kevin Bell

Working on a hardware independent C driver for the ESP8266 wifi module

github.com/Cloudnaut/AID

Jaxon Ramirez
Jaxon Ramirez

while (!AT_SendPayload(interface, "kekerino ist lolerino")
more like AIDS desu

Asher Brown
Asher Brown

for(int i = 0; i < sizeof(*arr)/sizeof(arr[0]); ++i)

Simple, clean, elegant

Attached: 1554454127158.gif (1.91 MB, 256x192)

Parker Barnes
Parker Barnes

jowforums.com/thread/70581127/technology
C as a first language
No.
This is how you get terrible programmers.
There are more than enough terrible programmers.
Newfag programmers should not be dealing with memory management before they understand the basic abstract fundamentals of programming.
C's syntax may be simple, but actually writing programs in it isn't.

Isaiah Morris
Isaiah Morris

Is taking an OOP Approach with C++ valid or is it considered heresy and will get me burned in front of the church?

Attached: 1541793058250.gif (179 KB, 680x502)

Joseph Wilson
Joseph Wilson

sizeof(*arr)/sizeof(arr[0]

Attached: 1512703916256.png (102 KB, 450x443)

Andrew Sullivan
Andrew Sullivan

too lazy to larp as le mastermind busy programmer today maybe tomorrow user

Xavier Diaz
Xavier Diaz

depends on what kind of work your looking for
for embedded i'd say
some can implementation according to either iso 11898 or iso 16845
a decent 14229 implementation goes a long way but maybe its not really applicable for a home project
rudimentary os with rate monotonic scheduling (or some offline scheduling), timer (for sleep/delays, etc), semaphores and priority inheritance can benefit you too
or just a hal and some drivers for any arduino/similar soc and peripherals

Brandon Martinez
Brandon Martinez

you fucked it up

Jaxon Davis
Jaxon Davis

Reposting because more people need to know about this makefile technique.

It works like this:

1. %.d : %.c (makes .d fike)
2. %.o : %.c %.d (makes object, triggers rule 1)
3. include $(wildcard $(.d)) (includes .d files built by rule above, only if they exist)

the first time make is invoked, it will build the .o files. the .d files are irrelevant for this run. for subsequent invocations, make will include the .d files and use the rules defined by the compiler instead of the pattern rule.

Benjamin Anderson
Benjamin Anderson

Is there even such thing as C++ heresy? C++ "supports all paradigms."

Kevin Peterson
Kevin Peterson

Lol, completely forgot I pushed this shit to the branch. Whatever. Enjoy my dummy strings for testing

Brayden Clark
Brayden Clark

Is there even such thing as C++ heresy?
en.cppreference.com/w/cpp/memory/gc/declare_reachable

Chase Cook
Chase Cook

So simple, clean and elegant that you couldn't even get it right. The absolute state of C koders.

Jordan Ross
Jordan Ross

Why should it? It was literally named "C with classes" originally.

Hudson Green
Hudson Green

Don't get the hate on tracing GC's desu. What is the time complexity of malloc? It actually isn't a trivial operation. But when you have a GC it can be implemented as a linear allocator.

Cameron Long
Cameron Long

Exactly but people still use C++ as C but with a different name for some fucking reason, just use C if you won't take any advantage of C++

Jose Gonzalez
Jose Gonzalez

jowforums.com/thread/70581127/technology
Found out what my issue was. I changed the name of a variable on the RIGHT side of a recipe which left it undef, and for some reason it would fail to acknowledge the pattern on the LEFT side.

Carson Stewart
Carson Stewart

meanwhile in C++

for (size_t i = 0; i < size(arr); ++i)

Kayden Myers
Kayden Myers

You have to manually declare something as reachable or unreachable? Seems kind of pointless. I guess it might have use in something like a GUI library where components are passed around like a village whore.

Kevin Cooper
Kevin Cooper

Reachable objects will not be deleted by the garbage collector or considered to be a leak by a leak detector even if all pointers to it are destroyed.
Retard

Aaron Bailey
Aaron Bailey

size_t
my condolences user

Camden Phillips
Camden Phillips

I think it's only for edge cases where there may be times where there's no recognisable pointers to an object, but it is still reachable, for instance in a xor'd doubly linked list, or if you were to use low bits in pointers as flags or something

Andrew Cox
Andrew Cox

Because they are retarded.
Properly written modern C++ especially looks nothing like C, even if you don't use OOP.
They are the same people that believe you still have to manually manage memory in C++.
C++ is a flawed language, but many poeple criticize it for the wrong reasons.

Nathan Ramirez
Nathan Ramirez

It's actually

for (auto &x : arr)

At least actually learn C++ before bragging, you dumb faggots.

Ryder Gomez
Ryder Gomez

not

for (auto &&x: arr)

Jayden Baker
Jayden Baker

Nonsense

Ryder Nguyen
Ryder Nguyen

Meanwhile in C++

for (auto value : arr)

Meanwhile in JS
for (const value of arr)

Jacob Myers
Jacob Myers

of

Attached: 1523386635027.png (23 KB, 645x773)

Jaxson Powell
Jaxson Powell

Your C++ version copies every element for no reason.

Joseph Nelson
Joseph Nelson

What if you want it to go from 1 to N-1, referencing i-1 at every step?

Tyler Diaz
Tyler Diaz

you still have to manually manage memory in C++
You do tho unless i missed something

Attached: 64345234414124.jpg (42 KB, 480x458)

Gabriel Robinson
Gabriel Robinson

How come?

Daniel Roberts
Daniel Roberts

foreach(var x in arr)

Attached: 1512908765345.png (28 KB, 488x463)

Ryder Jenkins
Ryder Jenkins

ok retard
devdocs.io/javascript/statements/for...of

Adrian Hernandez
Adrian Hernandez

you usually can use classes and objects that do this for you
for example you may hold your dynamic objects inside a vector<unique_ptr<t>> and then they will be automatically freed when the vector goes out of scope

Julian Diaz
Julian Diaz

Many classes like vector manage their own memory. And then you have smart pointers.

Gabriel White
Gabriel White

for x in xs

Attached: ea0.jpg (65 KB, 640x648)

Elijah Miller
Elijah Miller

That's still management. You still have to worry about object lifetimes.

Gavin Bennett
Gavin Bennett

why the copies? use the correct version from

Leo Rogers
Leo Rogers

luajit's ffi library is neat
i can't believe how easy it is to use

Aiden Kelly
Aiden Kelly

management, yes, but not manual management

Ethan Wright
Ethan Wright

You have to worry about object lifetimes in garbage collected languages as well, you just have no control over them
I'd rather write a three-line destructor and never think about it again than my program randomly hang because the mexican maid decided she wants to clear the heap now

Hunter Allen
Hunter Allen

From a user perspective how is it different than using Java for example? Sure Java has GC, but the way you actually write code is pretty much the same.

Jeremiah Wilson
Jeremiah Wilson

I have no idea where else to ask this.
For the past months I've been self studying math to go to my local community college, but a few days ago they updated their CS program to be pic related...
Liberal Arts
LIBERAL ARTS with an emphasis in CS
What in the fuck does this mean?
Should I find a new community college?

Attached: what.png (29 KB, 818x628)

Ayden Cox
Ayden Cox

You have to worry about object lifetimes in languages with built in garbage collection too.

If you never de-reference something it will never get cleared from memory. I had a memory leak myself the other day because I was being a bit overzealous and naive with a callback system I was making. Nothing ever got cleared because they remained in the callback chain even if the components were removed from all possibility of giving feedback / being reached by the user.

Owen Long
Owen Long

Not at all. In Java you don't have to worry about what kind of pointer you should pass and when it should be freed. It just happens when it's necessary.

Brody Bailey
Brody Bailey

mathematics is a liberal art

Asher Thomas
Asher Thomas

So basically like always using shared_ptr?

Isaac Rodriguez
Isaac Rodriguez

Even then you must worry about reference cycles.

Nathan Parker
Nathan Parker

stack is freed at the end of blocks, heap is freed when delete is called
This is too complicated
GC frees memory when Jupiter is in line with Saturn, and the electrons in the stratosphere spun just the right way
Ah, so much simpler and cleaner

Adrian Kelly
Adrian Kelly

But it says "Liberal Arts Degree"
only "with an emphasis in CS"
It used to be completely different on this page. I see "Liberal Arts Degree" and I feel instantly turned off.

Robert Taylor
Robert Taylor

reference counting like shared_ptr uses was an old garbage collection strategy but modern GC languages use tracing garbage collection instead.
i don't think it's very easy to mix tracing with manual memory though

Dylan Ortiz
Dylan Ortiz

c# can do it

Lucas Ortiz
Lucas Ortiz

The implementation is a bit difefrent, my point was more about how you use it. Memory management in modern c++ really isn't that hard anymore.
Although I still use raw pointers when I know I won't pass them around anyway.

Grayson Smith
Grayson Smith

return Review.find({ _id: {$in: this.reviews} }).then((reviews) => {
if (reviews) {
let total = 0
reviews.forEach(review => {
total += review.rating
});
return total / reviews.length;

Brainlet here. How do I actually make this return "total / reviews.length"? I'm probably forgetting something obvious.

Jacob Morris
Jacob Morris

IIRC, you can, but you need an idea similar to
the JVM's GC roots (basically things that the Garbage Collector is not eligible to clear in its tracing garbage collection and it handles manually) and managing those manually is a bit of a pain. Java's leveraging language-level features to determine GC roots. I'm sure with all of C++'s features you could probably figure it out, but eh.

Jeremiah Stewart
Jeremiah Stewart

Declare total outside of the if block

Ian Phillips
Ian Phillips

I spent whole day reading Java The Complete Reference by Herbert Schildt.

Jaxon Wright
Jaxon Wright

GIMP is the worst software I have ever used, and that includes games that crashed before you could play them.

Attached: fuckgimp.jpg (90 KB, 508x592)

Jonathan Cooper
Jonathan Cooper

Then what's a conservative art?

David Taylor
David Taylor

give us a review, user

Thomas Powell
Thomas Powell

I probably should've explained a bit better. Right now it's returning the promise (I think) as whole. Pic rel is what it's returning. I need it to just return the value inside the promise if that's possible.

Attached: Capture.png (13 KB, 352x240)

Jordan Cooper
Jordan Cooper

Then don't use a future, or just get the value from the pomise when it's ready.

Evan Butler
Evan Butler

Attached: 1445666074181.jpg (26 KB, 328x466)

Juan Ward
Juan Ward

liberal is from the latin word for freedom
the liberal arts were the shit that
every respectable non-slave member of society was supposed to know -- originally geometry, rhetoric, and philosophy

Robert Morales
Robert Morales

when brainlets think having to manually specify to your compiler that you can free/allocate when needed isn't manual management
The absolute state of (((modern))) programmers

Eli Murphy
Eli Murphy

As long as the compiler isn't so stupid I have to tell him manually how many bytes to malloc I don't care

Sebastian James
Sebastian James

It's because of gtk
Every gtk based gui I've ever used was terrible, always in the exact same way.
Then again, I suppose that's to be expected.
A library with documentation so bad it forces Linux man to use C++ is probably going to have fuck all effort put into end user experience.

Julian Howard
Julian Howard

The compiler isn't trustworthy and neither is your language.

Kevin Smith
Kevin Smith

Is there a way to make shared_ptr syntax simpler with macros or something? It should work like normal pointers, but with some new symbol for example
Object $object = new Object()
but the $ itands for a shared pointer.

Joseph Ortiz
Joseph Ortiz

Just use typedefs.
Also, don't use naked new.

James Smith
James Smith

It's so much worse than the interface.

All I wanted to do was copy the letters, move them around, and smooth things. You can't select a region and movie it. You have to cut and paste onto a new layer, and it collapses it back onto the original layer. BUT if you create a new layer after cutting, you can interrupt the paste and merge what you cut into that layer.

By default the layer view is only as big as what you copied the first time, so if you copied another thing to that later, it can't be seen because your view is restricted.

So let's say you have stuff moved. Now I want to smooth the background into a gradient. Too bad can't do shit. Let's try smooth. It destroys your opacity for no fucking reason. Literally no reason to change the opacity, but it does. Only in GIMP 2.9.5 did that add a "no erasing" option, which was already present in GIMP 2.1, but for whatever cocksucking reason they removed it.

And since you can't smooth regions directly, the image still looks like shit.

Cooper Nelson
Cooper Nelson

If you can't do it in preprocessor macros, then make a shell script or something to edit it. If you're on linux you can pipe the file and do a single substitution or pattern match harder. I prefer Perl because although it's more verbose, it's more portable (sort of, I'm sure you could use sed/awk whatever bullshit in the right windows environment)

Hunter Gomez
Hunter Gomez

I suck ass at this shit but you just put 0 effort in.

Attached: 1547658104661.jpg (70 KB, 508x592)

Cooper Wright
Cooper Wright

thanks,

Attached: meme.png (363 KB, 508x592)

Cameron Scott
Cameron Scott

In Rust, this is just

macro_rules! new {
($($t:expr)?) => {{
std::sync::Arc::new($($t)*)
}}
}

#[derive(Debug)]
struct Foo(i32);

fn main() {
let x = new!(Foo(42));
}

Attached: 1551757602196.jpg (58 KB, 514x524)

Gabriel Turner
Gabriel Turner

renchon a based

Liam Jones
Liam Jones

in C++ this is just

using std::make_shared;

Gabriel Edwards
Gabriel Edwards

It's so much worse than the interface.
I know, that's what I meant.

Let me put it another way.
The only programmers who use gtk are the people who see nothing wrong with it
Imagine the type of person who sees nothing wrong with a library that disrespectful and dismissive of devs and end users.
These are the kind of people who don't fix a significant amount invalid urls in their docs for months despite being notified of it multiple times.
Now imagine them making a GUI application.

GTK isn't just an interface library
It's a philosophy that believes in fucking over everyone.

Kayden Robinson
Kayden Robinson

weird, there's serious color banding on my phone but none on my PC. I don't know how this shit works, I give up.

David Walker
David Walker

template<typename Target =string>

what does the =string mean?

Isaac Thompson
Isaac Thompson

Target defaults to string if not otherwise given.

Michael Howard
Michael Howard

default parameter
so you can instantiate myclass<> and it will default to myclass<string>

Wyatt Bell
Wyatt Bell

default template parameters
if you leave the params empty or ignore them the type of Target will be string

Asher Anderson
Asher Anderson

std::sharer_ptr<T> is an atomically reference counted pointer that points to heap allocated memory. In Java a reference might be stack allocated if the optimizer realizes the scope can be reduced.

James Jenkins
James Jenkins

ah so I thought, thank you

Attached: 1452721870946.jpg (1.24 MB, 1080x1080)

Parker Johnson
Parker Johnson

weeb
degenerate
I'm not surprised.

Gabriel Thomas
Gabriel Thomas

should I really ALWAYS be using accessors instead of direct access to a variable? My professor shilled it pretty hard but it doesn't provide any advantage in this particular case.
My program already runs and all using a getter would do is add more lines to the program.

Christopher Ortiz
Christopher Ortiz

degenerate weeb website.

Aiden Campbell
Aiden Campbell

having getters and setters makes it easier to modify the implementation later without having to change the public interface or modify the calling code
also, it allows you to ensure that your object will only ever hold VALID data by doing all the checking in one central place, so callers don't have to bother with it

however, if you don't plan to modify this class later and if there are no possible dangerous/invalid values for your member variable, making it public is fine

Elijah Anderson
Elijah Anderson

Where?

Colton Parker
Colton Parker

right here!

Attached: 1452897258902.png (408 KB, 1000x1000)

Dominic Stewart
Dominic Stewart

Getters/setters are the most brainlet pahjeet tier OOP.
Out of every horrible thing OOP has birthed, I don't think anything gets more poo.
For the love of fuck, don't use them.
It's just a waste of time.

about the only time where they're actually useful is in multithreaded environments, to help deal with mutexes/atomic operations

Austin Miller
Austin Miller

Depends on the language but accessors are generally for custom getting/setting logic and getter only field

Samuel Reyes
Samuel Reyes

Make sure you will go to commit suicide today.

Christopher Sanders
Christopher Sanders

this is 4channel not Jow Forums or reddit so go back to where you came from

Attached: 1555096910941.png (38 KB, 249x387)

Nathan Davis
Nathan Davis

learn some english pajeet

Leo Perez
Leo Perez

Honestly, there are very few scenarios you want to expose a mutable variable without a layer of separation.

But immutable variables are fine. You should be using immutable variables more often, anyway.

Robert Martin
Robert Martin

anime degenerate still replies
I speak it.

Jace Adams
Jace Adams

no, you type it and do it poorly

Jonathan Sanders
Jonathan Sanders

static <E> void test(E e1, E e2) {
}

Why don't I get a compile time error when I call this Java method with 2 arguments of different type like this?

test("Hello", 2);

Benjamin Perry
Benjamin Perry

const Reality,Axiom = (I) => 'Nothing.else';
let that = Axiom,AXIOM = that;

var only = AXIOM,this = self['self'].get("self") || self;
consent('nothing',only,that);

Attached: Tsumugi.png (1.2 MB, 896x1024)

Christian Torres
Christian Torres

The only good OOP is Alan Kay's original concept. Most of the "real world" OOP is solutions to problems that never existed to begin with.

Nolan Smith
Nolan Smith

The variable in question is changed within the same class in which it is declared in Java. The project specification just includes writing setters and getters.
Most of this OOP shit is flying right over my head, functional programming was much more straightforward when I gave it a go last year.

Evan Jones
Evan Jones

Because E is resolved to be the most derived common base type. In this case, Object.

Adam Cook
Adam Cook

Wasn't the original concept an abstract messaging framework or something like it?

Ryder Perez
Ryder Perez

probably erasure shit making E an Object. But I am not sure as I thought constant numerics were not objects in Java

Carter Baker
Carter Baker

c++ standard template library is good as fuck
algorithms and containers following efficient well-optimized data structures and algorithms that the average retard couldn't implement, but usable by that retard as black boxes with no required knowledge of the internals

Dylan Butler
Dylan Butler

Thanks. Seems pretty stupid to me, but I'm sure there's a good reason.

2 is autoboxed into an Integer object.

Isaac Gray
Isaac Gray

Here's the thing. If different objects are sharing access to state-based properties then there's a good chance you're not practicing good object oriented design and are introducing heavy coupling.

I don't know anything about your project specifically, but the interaction between two objects should be on a concept level, not a nobs and levers level. And, sure, sometimes those concept level things can be expressed simply in a property (for example IsPaused / IsOn), but in my experience these are far more the exception than the rule.

But it might depend on what you're making.

Levi White
Levi White

Trying to make a portfolio for Java but not really sure where to start. What's a good project to work on?

Nicholas Evans
Nicholas Evans

a java youtube channel like all your ancestors

Alexander Hernandez
Alexander Hernandez

It's just a wordsearch puzzle generator for which I have to constantly be changing a char[][] array (adding words character by character, checking for overlapping etc) I don't think what we're doing here is even advanced enough to understand the importance of such OOP concepts.
Thanks anyway. I think it wouldn't hurt to drop the professor an email despite the fact that the program does run as expected.

Jaxon King
Jaxon King

Frankly, a "Wordsearch Puzzle Generator" sounds like a single object. It might need POJOs to do its job, but POJOs do not need getters and setters.

Yeah, I don't think that problem space is big enough to highlight OOP concepts.

Jacob Rogers
Jacob Rogers

open youtube tutorial
hey guys we're gonna make a c++ program for X
proceeds to use printf

Attached: 1501697659652.jpg (22 KB, 351x351)

Robert Murphy
Robert Murphy

open youtube tutorial
title and description are entirely in english
"a welcome kurjeen jeedah Java tutorial ravjeesh harkurakesh"
I remember asking a friend who was at least part Indian about one of those videos, he watched it and said it wasn't in Hindi, it was actually ALL IN ENGLISH, just really fucking broken English.

Wyatt Wright
Wyatt Wright

I don't get the youtube meme.
Who actually watches programming tutorials?
Just download an IDE and start experimenting.

Nathan Mitchell
Nathan Mitchell

it's for homebrew for a console, the docs aren't the best and the tools and libs are all community made. All example code is written in an ancient C style, so I was trying to see what a c++ would look like but instead I find retards using C while compiling it as c++

Cameron Roberts
Cameron Roberts

It's nice to see the basics, when you start out it's hard to even ask the right questions unless someone shows you the absolute basics or you read a book.
It's probably not the most efficient way, but I find tutorial videos comfy.

Jordan Hill
Jordan Hill

What does /g think of Lua? Worth picking up? I know Ruby C and just finished up with Java. What's lua good for?

Michael Walker
Michael Walker

I really don't like LUA personally, the syntax is just weird. It seems that they just tried to make it different on purpose. If I remember correctly array indexing also starts with 1.
It's used for scripting, the main advantage is that it's very small.

Kevin Wood
Kevin Wood

Lua used to be the de-facto scripting language for interacting with programs, adding add-ons, etc. But nowadays I think a lot of it's Python.

Jaxson Parker
Jaxson Parker

It's used for scripting like says because the C API is so simple and easy to use. The language itself is not that good.

Justin Ortiz
Justin Ortiz

Arrays start with 1? What the fuck. Well shit, I'll have to take a look I guess and decide. Maybe I'll grab python or js. I always thought it looked visually appealing and easy to work with for scripting.

Levi Hughes
Levi Hughes

Thanks Jow Forums, saved me a lot of time. Guess I'll just pick up python and roll with that. Python 3 catch on yet or is it still on 2?

Matthew Fisher
Matthew Fisher

Lua doesn't actually have arrays, just dictionaries. There are array-like functions in the standard library that start indexing at 1 (using dictionaries where the keys are integers), but you don't need to use them to get the same functionality.

Owen Lewis
Owen Lewis

pdf's here for learnings
smtebooks.com/

Joseph Wright
Joseph Wright

Do you ever feel lonely while programming?
Why can't girls program, so that we could have gfs to program together with?

Michael Powell
Michael Powell

I defy you to tell me why that's worse than the stream fuckery that C++ thought was a good idea

Jayden Foster
Jayden Foster

I never feel lonelly when programming, I really enjoy it.

Charles Lopez
Charles Lopez

inferior brain structure, settle for a cute south korean trap

Jeremiah Taylor
Jeremiah Taylor

it's unsafe

Jack Hill
Jack Hill

I only feel lonely when I'm not programming

Joshua Moore
Joshua Moore

K&R exercise 1.23

Attached: knr-1-23.png (40 KB, 480x818)

Jace Morris
Jace Morris

picture_for_ants.png

Cooper Anderson
Cooper Anderson

Do you ever feel lonely while programming?
no, but I feel sad because I never make anything that other people will use and find useful and will thank me for sharing it with them

Attached: 1540694978690.jpg (61 KB, 639x629)

Elijah Reed
Elijah Reed

In C# (WPF and others) you usually have additional logic in getters and setters of viewmodel properties, so it helps (and C# actually has an alright syntax for it). Other than that, the only other places I use them (in any language) are
1)read-only access
2)doing some sort of aggregation over class' fields (though that's not really a simple accessor anymore)

Jason Adams
Jason Adams

and C# actually has an alright syntax for it
This. In C# it doesn't matter because it's so easy to swap a property for a getter/setter with logic.

Thomas Scott
Thomas Scott

I use advanced C++17 at my work and for quick debugging I still use printf. Fuck streams.

Isaiah Lee
Isaiah Lee

This is my first program i made by myself without importing from the web. How shitty it is?

#include <stdio.h>
int main()
{
int first = -2;
int second = -1;
int cons;
int printcons;
int firstcheck;
if (first>-5);
firstcheck = (first + second); /*This is -3 */
cons = (6 * (firstcheck / second)) + 3;
printcons = (cons - 2 * second);
if (cons>0)
printf("cons was bigger than 0 because it was %d\n", printcons);
else
printf("cons was smaller than 0 because it was %d\n", printcons);
return 0;
}

Lincoln Thomas
Lincoln Thomas

I like printf more than cout too.

Blake Barnes
Blake Barnes

but for what reason
I haven't much experience with it but I'm still wondering

Kevin Howard
Kevin Howard

I need to learn c++ in a few days
I already know c and java
Any recommendations?

Wyatt Peterson
Wyatt Peterson

read g++ source code and figure out what it does

Hudson Walker
Hudson Walker

How shitty it is?
Very. But that's not what's important here.
You made it yourself and so should be proud of it.
It's not much compared to what professionals do every day, but you are not a professional, you are just starting out.
Good job, user. Focus on self-improvement and don't compare yourself to others who have been practicing for years.

Samuel Anderson
Samuel Anderson

It's pretty fucking shitty but that's ok user

Attached: 1546013011869.jpg (54 KB, 556x720)

Luke Martinez
Luke Martinez

What's a cons?

Xavier Reyes
Xavier Reyes

it's cute

Anthony Jenkins
Anthony Jenkins

I've never encountered a language that does anything even remotely similar to cout for strings. Their syntax is far more similar to printf (although usually have helpful flavor syntax so you can put the variables in-place rather than at the end).

It was the wrong solution to the wrong problem.

Mason Wood
Mason Wood

printf is bad because it's type unsafe and because it's not extensible
something like printf like fmt::print or rust println is good though

Adrian Moore
Adrian Moore

I don't think i will advance too much. It took me a couple of hours to do it. It's not about others, but the guides that are shitty.
en.wikibooks.org/wiki/C_Programming/Structure_and_style
learn-c.org/en/Hello,_World!
Like why the first one gives int main(void) and the second one is without void. What's void? None of them give any clue.
It's meaningless. Also nice quads

Michael Campbell
Michael Campbell

Stroustup's books are not bad.

Jeremiah Jackson
Jeremiah Jackson

Most OO languages use streams for I/O to the console.
The reason is simple: You should program to the interface, not the implementation.
Basically you can swap writing to the console with writing to a websocket or a file or any other output stream and the program will still work exactly the same way without having to change anything other than one definition somewhere.

Noah Hernandez
Noah Hernandez

printf("0x%04x\n", 0x424);
std::cout << "0x" << std::hex << std::setfill('0') << std::setw(4) << 0x424 << std::endl;

Ian Collins
Ian Collins

the guides that are shitty.
Yes, I struggle with this too and I have been programming for years.
It gets a bit easier the more you program, but part of learning programming is scrounging together information from all over the place and turning it into knowledge.
There's no difference between int main() and int main(void), it's just an artifact of C being very old. void basically means that the main function has no arguments, but the more natural way to write that is by just not writing anything at all.
You should try to learn loops and/or arrays next, as that will let you unlock a ton of cool things. Then functions after that.

Benjamin Bell
Benjamin Bell

to add to this , tour of c++ is short and assumes you have programming knowledge, can probably read it in 2 days. It's more of an overview but it does show you the basics how to use things, you'll need to look up elsewhere for more details

Dylan Bennett
Dylan Bennett

Meanwhile, in Rust:
doc.rust-lang.org/1.5.0/std/macro.write!.html
It uses a format string, like printf, but it's type checked and extensible, and it works for an arbitrary stream.

David Bailey
David Bailey

We're not talking about data streams, we're talking about cout / cin streams that look like this cout << 1 << 2 << 3 << 4 << 5 and are retarded and convinced Java that operator overloading was a mistake.

Besides, you shouldn't be using simple streams for logging, you should use a routing/filter sink-based approach for multiple parallel output sources.

William Morris
William Morris

Cute doll

Joseph Robinson
Joseph Robinson

thanks

Cooper Roberts
Cooper Roberts

cout << 1 << 2 << 3 << 4 << 5
The concept is reasonable and normal in FP.
It's basically just a bind operator like >>=.

Besides, you shouldn't be using simple streams for logging, you should use a routing/filter sink-based approach for multiple parallel output sources.
You should be using a logging framework that has already solved this for you, but they most likely did it using streams of some sort under the hood.

Leo Gray
Leo Gray

What font does /dpt/ use?
I've been using bitmap fonts for years such as Terminus (I'm stubborn), but I'm lately experimenting with more modern-looking fonts.
So far, I really like Hack and Fira Mono. What are your favorites?

Attached: 1533534185775.png (2.61 MB, 1488x2088)

Owen Green
Owen Green

Redpill me on logging vs printf

Wyatt Long
Wyatt Long

Ligatures are aids.

Kayden Smith
Kayden Smith

I assume cons means computed constant, that threw me off a sec...
Choose better names ("the most difficult problem in programming") and indent inside

 { ... } 
blocks (possible exceptions for goto labels and/or debug statements, depending on style guide).
Looks okay after that.

Chase Bennett
Chase Bennett

Yeah, I know it exists in FP, but if they're using it to format strings then they are as retarded as C++ was when they made string formatting pipe-based. Human-readable solutions to human-readable problems. Surely FP languages get this simple concept?

second part
Streams don't really exist "under the hood" They're a transactional concept. Data in from one source, out to another. Under-neath the hood logging libraries are using Queues. As are streams.

Jordan Edwards
Jordan Edwards

Pragmata Pro

Julian Mitchell
Julian Mitchell

Consolas

Tyler Morales
Tyler Morales

Is that a photo of you? You're pretty cute.

Caleb Green
Caleb Green

It's basically just a bind operator like >>=.
You have no idea what you're talking about.

Gavin Lopez
Gavin Lopez

Iosevka

Asher Campbell
Asher Campbell

alright fair enough

John Long
John Long

Do a search for "introduction to c lecture notes". With any luck some of the results will be lecture notes for college/university intro courses.

Don't click anything that looks newer than 2010-2012 or so, or ANYTHING with the stench of "publicity". Google's preference for Wikipedia entries counts as free publicity. Anything shilled on Reddit (except possibly K&R book, which is still overrated) is the plague.

BTW some of the shilled codecamps and MOOCs etc (i.e. Yale CS50) *can* have good content, if you squint hard enough... But just don't, save yourself.

Read 3 or 4 just in case one is a dud. This one is probably okay... vssut.ac.in/lecture_notes/lecture1424354156.pdf

Nathan Carter
Nathan Carter

Would this be a decent laptop for coding to use while I'm at uni?
amazon.com/VivoBook-Portable-i5-8250U-processor-S510UA-DS51/dp/B078YMY5VZ/ref=sr_1_19?keywords=laptop&qid=1555535241&refinements=p_89:Asus&rnid=2528832011&s=gateway&sr=8-19

Aaron Smith
Aaron Smith

$650 for a uni laptop
jesus fuck dude, just buy some 2nd hand thinkpad for couple hundred, or whatever they go for these days.

Nathan Williams
Nathan Williams

So C++ constexpr + user defined literals mean I can do something like this?

const int result = "int foo() { return 5; } int main(){return foo();}"_compile_and_exec;

I.e compile and execute C code at compile time? (If I write a constexpr C compiler)

Jeremiah Robinson
Jeremiah Robinson

yes
good luck writing one with the limitations on constexpr though
in lisp this is just eval

Carter Ward
Carter Ward

Y-yes...

Xavier Carter
Xavier Carter

Way too expensive for pretty much anything you'll have to work on while at college.
You can get a perfectly adequate one for half the price.

Christopher Bailey
Christopher Bailey

I actually like having more than 256gb of storage, but it's definitelly enough for most uses.

Levi Cox
Levi Cox

Iosevka
This. I've been trying out fonts for months and this is my favorite so far.

Honorable mentions include PT Mono, SF Mono and Fantasque Sans Mono.

As for bitmap fonts, I really like Tamzen and Fixed SemiCondensed.

Jack Perez
Jack Perez

Why would this be happening?

Attached: Capture.png (94 KB, 1849x801)

Jason Adams
Jason Adams

What about this?
amazon.com/Flagship-Processor-Celeron-soldered-Bluetooth/dp/B07NJ6CPZR/ref=sr_1_16?keywords=laptop&qid=1555538694&refinements=p_89:Asus&rnid=2528832011&s=gateway&sr=8-16

Camden Bailey
Camden Bailey

array[start] = array[end];

Adam Mitchell
Adam Mitchell

array[start] = array[end]
First step:
array[0] = array[5]
Index out of bounds.

Tyler Martin
Tyler Martin

Dude even pajeets can understand java. It's not hard.

Attached: serveimage(38).jpg (57 KB, 645x729)

Noah Kelly
Noah Kelly

Hate it when make stupid mistakes like forgetting indexes start at 0. Thanks for helping a noob out.

Angel Sullivan
Angel Sullivan

Some languages like Perl can use periods for string concatenation, so you can do print STDOUT "hello: " . $number . " is your number\n"; It's not much prettier than print STDOUT "hello: ${number} is your number\n";

Courier New in Notepad++ apparently. I usually use the default font for everything. It really doesn't matter compared to say, a theme. In Cataclysm DDA I use VeraMono

Elijah Robinson
Elijah Robinson

actually, if the index was out of bounds, what the fuck was that -858993460 number it grabbed that was out of the bound?

Leo Jenkins
Leo Jenkins

You can do

end = sizeof(array) / sizeof(array[0])

On another line. It will be determined at compile-time so should compile the same way, but now you don't have to specify 5.

Angel Miller
Angel Miller

garbage

Sebastian Anderson
Sebastian Anderson

Grab the code, compile it yourself, check the assembly

Jace Diaz
Jace Diaz

only works if the array is defined in local scope

Andrew Wright
Andrew Wright

It is. Kill yourself you dumb fuck.

Sebastian Garcia
Sebastian Garcia

Replace end with

 int len = sizeof(array) / sizeof(array[0]); int end = len-1; 
. Include a comment saying you are reversing an array in place.

Hunter Ward
Hunter Ward

flagship

Brayden Green
Brayden Green

zedshaw.com/2017/08/26/what-if-it-worked/

Is he right?

Attached: 1540323263582.jpg (35 KB, 600x600)

Daniel Watson
Daniel Watson

I know, but you're still wrong.
Here's why:
end is declared before array in his code, therefore

int start = 0, end = sizeof(array) / sizeof(array[0]), array[] = {1,2,3,4,5};

wont actually compile.
I will now await your backpedaling response about how he souldn't declare multiple variables on the same line, and such.

I made my comment assuming , was new to C, to point out that your trick only works in local scope.

Brayden Howard
Brayden Howard

The thinking man's solution here is to change lines 10-12 to

array[start++] = array[++end];
array[end] = temp;
}

Grayson Diaz
Grayson Diaz

haven't really read it, don't care for any version of python, but he's one to accuse others of narcissism

Nicholas Walker
Nicholas Walker

You can do

end = sizeof(array) / sizeof(array[0])

On another line.

Reread my post you dumb cunt. You were just looking to be a retarded shitposter and you did it as soon as you found an opportunity. Congrats on getting me to reply. Holy fuck. I literally used the name of the variables. I said to do it ON ANOTHER LINE. LITERALLY. Kill yourself.

Lincoln Kelly
Lincoln Kelly

I said to do it ON ANOTHER LINE. LITERALLY. Kill yourself.
then where's your type declaration?

Daniel Foster
Daniel Foster

github.com/kw-udon/constexpr-8cc

Caleb Watson
Caleb Watson

If it's on another line you don't need one because it's already declared. You're just pretending right?

Xavier Perry
Xavier Perry

The thinking man's solution would be

*(array+(start++)) = *(array+(++end));
*(array+end) = temp;
}

Landon Green
Landon Green

I prefer:

*(++start[array]) = *(++end[array]);
*(end[array]) = tmp;

Austin Long
Austin Long

Should it be easier for compilers to optimize tail recursive functions than something with loops?

Carter Peterson
Carter Peterson

Quit your job
Make video games

Attached: boomerre.gif (20 KB, 192x192)

Matthew Foster
Matthew Foster

You're just pretending right?

int start = 0, end = 5, array[] = {1,2,3,4,5}, i = 0;
int temp;
end = sizeof(array) / sizeof(array[0]);

No I'm not.
What you're suggesting here is cancer(defining multiple variables on a single line)++(redefining one of those variables on another line).

Jonathan Allen
Jonathan Allen

That's the idiot's choice. The way to go about it is to keep at your job and work on games in your free time until one of the games you shit out takes off. Indie games is just a luck of the draw, it's completely random if you're going to make it, not worth betting all your cards on it.

Blake Jenkins
Blake Jenkins

Is there any point in learning Haskell if you don't have a background in mathematics? It's fucking torture to learn compared to other languages.

Jaxson Ortiz
Jaxson Ortiz

No need for excessive parentheses.

*(array+start++) = *(++end+array);
*(array+end) = temp;
}

The thinking man would do a one-line xor swap with the comma operator, but with three layers of macro indirection.

Sebastian Thompson
Sebastian Thompson

what are the asterisks for? the brackets already dereference the pointer, no?

Dominic Collins
Dominic Collins

Fucking delete your post and think again of what you said before others get a chance to read it.

Zachary Thompson
Zachary Thompson

No, but it makes it easier to read, as operator precedence is real flaky between languages.

Adrian Nguyen
Adrian Nguyen

Why did you make a duplicate general thread?

Noah Peterson
Noah Peterson

Because the other one's been stagnant for 48 or so hours

Dylan Harris
Dylan Harris

To my man '3777
Enjoy your wage-slavery

Owen Bailey
Owen Bailey

The other one was made 4 threads ago, it wasn't good enough then and it's not good enough now. it's just being bumped by stray retards and reddit memers.

Thomas Gutierrez
Thomas Gutierrez

To my man '836, enjoy having to crawl back to your parents when your first game inevitebly flops.

Jose Hall
Jose Hall

No. Loops are just straightforward goto, tail recursion requires advanced lies on the part of the compiler.

James Rivera
James Rivera

You are actually this dumb. I'm sorry I was fooled into believing you were actually serious.

Ryder Sanders
Ryder Sanders

int x = 100;
while (x --\
\
\
\
> 0)
printf("%d ", x);

Justin Fisher
Justin Fisher

there have been a bunch of members of late who take /dpt/ memes too far and in retarded directions
screaming because someone used a "reddit" joke for a thread OP is one example

Brayden Turner
Brayden Turner

Enjoy your wage-slavery
The prospect of owning your own house one day, in exchange for spending 7.5 hours a day at a comfy, no stress job, with great co-workers is actually pretty great.

Ian Gray
Ian Gray

Tell me how I'm wrong, prove your excellence.

Thomas White
Thomas White

Haskell is based on rigorous mathematical formalism, but you don't have to be a mathematical genius to use it.
Some basic knowledge about lambda calculus, however, is advised.

Ethan Perez
Ethan Perez

all of this cope

Attached: fo76.png (1007 KB, 831x794)

Zachary Peterson
Zachary Peterson

Are you really this dense?

int start = 0, end, array[] = {1,2,3,4,5}, i = 0;
int temp;
end = sizeof(array) / sizeof(array[0]);

Samuel Rogers
Samuel Rogers

Why do you write code like this? Who are you trying to impress?
b-but it's more effi-
No. Simpler, more readable solutions end up being compiled to the same code anyway.

Brayden Kelly
Brayden Kelly

Where is this from originally?

Caleb Jones
Caleb Jones

Now explain why you declare end on the same line as the rest, but temp on a separate one.

Jackson Gomez
Jackson Gomez

it's right though isn't it?

Eli Barnes
Eli Barnes

That's the joke, you dense fuck.
I'm not him, I'd do each variable on a separate line.

Sebastian Robinson
Sebastian Robinson

it's the lesser known "slides to" operator, only used by senior C developers

Lincoln Edwards
Lincoln Edwards

slowing down your compiler with long variable names
what are you, a lamer?

Nathaniel White
Nathaniel White

I'm not him, I'd do each variable on a separate line.
every would, that's my point

Jayden Diaz
Jayden Diaz

I wouldn't write code like this. Is sarcasm too radical of a concept for you?

Hunter Thomas
Hunter Thomas

of late
newfag
"reddit"
it even has the filename and he was shitposting about /r/ProgrammingMeme in the thread before, it's a shitpost thread

John Reed
John Reed

but you don't have to be a mathematical genius to use it.
It's not the ideas behind the language that are hard to understand, it's how they're described. Most Haskell learning material feels like the author was trying to use as few words as possible instead of conveying their ideas clearly, or they think the word "computation" makes them sound smart.
Honestly I don't think the language is bad, but it has almost zero pick-up-and-play potential, which is a huge barrier to entry for a general-purpose language.

Brayden White
Brayden White

OP image autism has a long history on /dpt/.

Attached: The-Correct-Image.png (389 KB, 934x1000)

Xavier Murphy
Xavier Murphy

reminds me of the tadpole operator

Attached: tadpole-operator.png (19 KB, 782x320)

Christopher Kelly
Christopher Kelly

My game that it feels like it will never get done.

Btw anyone know if I can use MBR on a M.2 disk or do I HAVE to use GPT?
Want to get a M.2 but want to be sure I can still use TrueCrypt.

Attached: go-with-the-flow.jpg (232 KB, 887x900)

Jaxon Lee
Jaxon Lee

Correct Image
wrong

Attached: 1402598137381.jpg (371 KB, 1045x822)

Colton Young
Colton Young

Haskell is based on rigorous mathematical formalism

Attached: 1550180380162.png (229 KB, 628x708)

Eli Gonzalez
Eli Gonzalez

i know

Jose Jones
Jose Jones

Hah, that is beautiful. Better than the down-to operator.

Zachary Allen
Zachary Allen

signed overflow is UB

Ian Gonzalez
Ian Gonzalez

Attached: HR.png (32 KB, 640x480)

Jack Robinson
Jack Robinson

Have you read the purple book? It's written for people with zero programming and mathematical background in mind.
Although I agree that many resources aren't very good, and assume the target audience already knows some concepts such as functors or monoids.
It's a shame, because the language has great potential, but this fact just enforces its impenetrable image.

Carter Sanders
Carter Sanders

asuka
c
how the fuck can you fuck up two things at once

Aiden Wright
Aiden Wright

It certainly is more than most other programming languages.

Noah Carter
Noah Carter

the whole cabal/stack trashfire is also a barrier to entry
why the fuck would anyone think that a repo should also serve as a "request for comments" "send in whatever bullshit you shit onto your keyboard" thing.
At least stack is curated but then in the inevitable case where you need something outside that collection then you're just fucked at square 1 again.

The best thing I learned from my time with haskell was that I am fucking lucky that CRAN is so based

Kevin Kelly
Kevin Kelly

absolute garbage

Grayson Moore
Grayson Moore

please respond

Attached: hermione05.jpg (378 KB, 1200x1600)

Jacob Long
Jacob Long

its a joke idiot

Bentley Russell
Bentley Russell

sometimes i envy the cniles
i mean sure, the C language lacks a shitload of basic productivity features, is filled with technical limitations caused by being developed for an ancient abomination of a computer, has a shite preprocessor, and barely even tries to evolve
but the AST's so simple you could parse it by hand
writing language extensions is pisseasy

Kayden Bell
Kayden Bell

Just passed the 2000 commit mark in my project.

Jaxon Morales
Jaxon Morales

I would think so, it's not a programming question though. Try >>>/sqt/ or >>>/fglt/ if you're installing gnu/linux.
also wait more than 11 minutes before bumping your question, /dpt/ is probably not as fast as where you came from.

Nicholas Lewis
Nicholas Lewis

are you the os guy

Benjamin Wilson
Benjamin Wilson

I am, hi :)

Attached: catoffice5.jpg (26 KB, 394x400)

Jose Smith
Jose Smith

what are you saying, user?

Attached: hermione07.png (1.16 MB, 1024x768)

Isaiah Phillips
Isaiah Phillips

I really fucked that up, //boards.4channel.org/g/catalog#s=sqt and //boards.4channel.org/g/catalog#s=fglt
fuck off, I guess

Carson Torres
Carson Torres

Common Lisps CLOS is also very good. It has a MOP, multiple dispatch, before, around, after, EQL methods, a mechanism to update and change classes of already instantiated objects and more.

Even Alan Kay said it's awesome.

Justin Wilson
Justin Wilson

much obliged

Attached: hermione08.jpg (245 KB, 1682x2100)

Liam Wilson
Liam Wilson

There is no point in learning haskell regardless of your background.

Jace Russell
Jace Russell

this but any programming language

Christian Martin
Christian Martin

Have you read the purple book? It's written for people with zero programming and mathematical background in mind.
I'm trying it, but it's irritating if you don't need a first-principles lesson. It's just baffling how it's never assumed you come from non-FP programming
That too. I'm thinking of trying OCaml instead.

Sebastian Cooper
Sebastian Cooper

Attached: reverse.png (31 KB, 480x624)

Landon Brown
Landon Brown

She was so hot back then.

Gabriel Howard
Gabriel Howard

are you doing a screenshot method that lets you "screenshot" more than what's on the screen? I've wanted a solution for that for a long time

Luis Kelly
Luis Kelly

if(!a) return;
assert(a);

Dominic Lewis
Dominic Lewis

asserts can be disabled at compile time, though. It's not a substitute for runtime checks.

Juan Torres
Juan Torres

Any haskell nerds around?
I have a type system question: I'm writing a compiler for a toy language (yes for a class, no I'm not asking for my homework answers, I'm literally doing this alone on the professors request, nobody else is using haskell)
My token grammar is something like

data Operator = ADD | SUB | MUL | DIV | UNARY | BYTECAST deriving (Show, Eq)
data Stmt = FIXED_STMT_A | FIXED_STMT_B | FIXED_STMT_C ...

data Kind = ID String | Func String String | Operator Operator | Stmt Stmt | ...

data Token = Token { kind :: Kind, line :: Int, col :: Int }

The details aren't super important. Mostly it's the Kind implementation, it seems fucking stupid. I have operators, expressions, statements, class declarations, function declarations, all with their own identifiable grammars that I can distill, but I'm really not sure how to approach distilling it away from having to extract kind out of the Token data type every goddamn time (kind was used because type is a reserved keyword and record syntax didnt like it).

Where is my stupid point and how do I fix?

Thomas Turner
Thomas Turner

have to repeat the process a couple times, with the precise command sequence. it took awhile to work kinks out of the process...

Owen Hall
Owen Hall

that's the point
don't pass in invalid input, no problem

Brayden Richardson
Brayden Richardson

Haskell requires no math background to learn. It's based in it, and refers to it, but it's ultimately no more high-level or abstract than the entire OOP model. You don't need to know math to use haskell. You DO need to be able to break away from procedural thinking.

The hard part in explaining haskell is that there's nothing to explain, the language its insufferably simple because its root is so abstract. This means it's insanely expressive, and there is no magic, just lifting, shifting, moving, and abstracting. But it also means that when somebody asks you "whats a monad" you have to explain that chain of abstraction using lego bricks.

dev.stephendiehl.com/hask/#monadic-myths

The purple book is your best bet. Haskell is a language your brain has to chew on, just as any FP language is. The biggest adjustment is procedural to FP, except Haskell FORCES you to stay in the FP realm. Look up exercism.io and absolutely refuse to google the solutions to their haskell course, it's actually a really good way to get used to it.

Chase Martinez
Chase Martinez

why are python's error-handling functions named as

try:
statement
except ExceptionCase:
statement

instead of something more readable for humans like
try:
statement
incaseof ExceptionCase:
statement
?
can I change this in its modules somewhere?

Noah Lopez
Noah Lopez

she turned 29 a couple of days ago.
i bet she will still be childless at 35.

Jaxon Gonzalez
Jaxon Gonzalez

#ifndef NDEBUG
#define free(p) ((void)(free(p), (p) = NULL))
#endif

Yes or no?

Hunter Adams
Hunter Adams

not sure what exactly you want, do you have an example where you're using it?

Blake Ward
Blake Ward

telegram bot today spaming all my user list with img files was taking all from Jow Forums archive

Ryan Cruz
Ryan Cruz

Oh, so you couldn't say, "screenshot" the past 500 lines in your terminal, most of which are off-screen?

Jace Myers
Jace Myers

just use sepples

Adrian Young
Adrian Young

cabal/stack/toolchain issues drained all your enthusiasm from learning haskell
idris sounds much better anyhow
idris is based on haskell and the ecosystem would be even more barren if it exists at all
wake me in 50 years

Christopher Diaz
Christopher Diaz

Why not just use a keyword people already know?

try:
statement
if ExceptionCase:
statement

or
try:
statement
case ExceptionCase:
statement

Benjamin King
Benjamin King

just use catch

Andrew Howard
Andrew Howard

So I lex a string and turn it into a series of Token types, and depending on the character (or collection of characters) I give that Token a kind of type Kind
If it's '+' then it's Operator ADD, '-' Operator SUB, etc
But then later when I'm parsing these things, I end up having to do Token{kind=Class c} or Token{kind=Operator MUL} fucking everywhere, and it makes it a huge pain in the dick to do pattern matching

Angel Turner
Angel Turner

Because python is a language designed by "Literally Some Guy" and has never been well implemented, ever. It's objectively the worst programming language in common use, and that's not just a "EWWW I HATE IT!"
I mean it's literally, by all reasonable design, according to literally anybody who has ever had any experience in programming language design, implementation, parsing, and compilation beyond their one CS undergrad course, is the fucking worst. C isn't even expressible as a context free grammar and its still a more coherently made language.

Brody Hall
Brody Hall

Just do an inline function on

inline void xfree (void *ptr) {
if (ptr) { free(p); p = NULL; }
else { // explode for trying to double free
}
}

Unless you're building cutting-edge computational software the cost incurred by malloc/free is nonexistant, just wrap that shit into inlined safe xmalloc and xfree functions and enjoy your absolutely 0 performance loss and 100% safety increase
I also recommend doing the same for strcpy and strcat, just make xstrcpy and xstrcat that inline themselves and make sure all the boilerplate safety is in place. You're not writing hyper-performance software, these are not your problem areas.

Jason Russell
Jason Russell

just use mallopt to tell glibc malloc to die predictably on double free.

I don't understand why half the safety features and asserts of glibc malloc aren't on by default.

Dominic Edwards
Dominic Edwards

No. Macros that modify state silently are fucking shit.

#define free(p) do { free(*(p)); *(p) = NULL; } while (0)

would be slightly more acceptable.

Jaxson Moore
Jaxson Moore

just wrap that shit into inlined safe xmalloc and xfree functions and enjoy your absolutely 0 performance loss and 100% safety increase
I wouldn't call straight-up crashing to be "safe", but honestly that's the best course of action for a lot of software.

Sebastian Robinson
Sebastian Robinson

Not a single one of those solutions is hard to read. At all. Also, those won't end up being compiled the same in any kind of real codebase, the compiler will optimize away a literally infinite number of convoluted solutions to things in toy programs because it's straightforward. When you have these things inside of complex patterns, it can't. Some of these are objectively faster, and not at all less readable.

Joseph Brooks
Joseph Brooks

which lexer generator is the best
and no i'm not writing my own
fuck that

Kayden James
Kayden James

Question. So I need to populate one array with 20 random integers and then use a 2nd array to keep track of how many times each integer was generated and then print the results. I used a really long hard coded method to try and do this, but when I looked at the official solution, it was this:

int main()
{
int array1[20], i;

int array2[101] = { 0 };

for (i = 0; i < 20; ++i)
{
array1[i] = (rand() % 101);
//line below is what I'm not sure about
array2[array1[i]]++;
}

for (i = 1; i <= 100; i++)
{
if (array2[i] > 0) printf("%d\t\t%d\n", i, array2[i]);
}
return 0;
}

How is this code working? Shouldn't array2 be storing whatever value is returned for the ith element of array1? So array[1]=66, shouldn't array2[1] also be equal to 66? Yet when I printed every value of array2 I found that array2[1]=0 (assuming for argument's sake the value 1 was never generated) and array2[66]=1. I just don't understand how its working.

Jonathan Moore
Jonathan Moore

Don't do that.

Use a name different from the standard library name. And be mindful of other pointers that might have referenced the same object.

But it should be okay with another name i.e.

 #define FREE(p) do { free(p); (p) = NULL; } while(0) 

Liam Reyes
Liam Reyes

But why? If I pass a null pointer to free, it will segfault anyway. My approach can be applied to code that already exists without needing refactoring.
What should malloc do?

void* rc;
rc = malloc(n)
if (!rc)
abort();
else
return rc;

That's about the only thing I can think of.
we now introduce spicy new library options into the mix
It's not just double free. For instance, dangling pointer issues get fixed into a nice, clean segfault.
That's wrong, my macro mutates no observable state. Your macro on the other hand invokes UB.

Carter Rodriguez
Carter Rodriguez

But then I'd have to change the code. My macro is almost zero cost and works with existing codebases.

Jack Cooper
Jack Cooper

If you run into free/malloc issues you should crash, that's kind of par for the course.
Well not on free. I think I wrote that backwards. Drop the else statement, is the pointer is already null then just do nothing. The point of xfree is to check and make sure the pointer exists before trying to free it, avoiding double frees or null frees.
xmalloc should fucking explode though, if you malloc and your result is null, explode. Yes that will probably never happen on modern hardware unless you're doing something insane, but again unless you're writing cutting-edge performance software that isn't your bottleneck

They're all fucking shit and lexers are easy you pussy

array1[i] = (rand() %101)
Assigns a number from 0 to 100 into array1[i]
array2[array1[i]]++
The value in array1[i] is used as an index into array2, and then that value is incremented.
So if array1[i] == 5, then array2[5] is incremented by 1.
Then they print out some shit.
This is a really fucking stupid solution but they're using the Int value from array1 as the index into array2

Alexander Ross
Alexander Ross

You would have to pass a pointer to the pointer for that to work as a function.
free does not segfault if you pass in NULL. free(NULL) is a noop.

Christopher Long
Christopher Long

The value in array1[i] is used as an index into array2, and then that value is incremented.
That makes sense. Thank you user

Noah Roberts
Noah Roberts

re: free - I was being stupid, see For malloc, do malloc how you would expect and actually do the null check. It's a tiny thing but if you're going to wrap these calls anyways you might as fucking well.

Also don't use preprocessor macros to do this shit, that's fucking insane. Inline keywords aren't a guarantee but they're effectively the same and you don't run into all the annoying string-replacement issues with macros, and you don't have to do crazy nonsensical bullshit. You just write a normal function that everybody can understand.

Michael Thomas
Michael Thomas

Smart pointers are also slow. A giant tree of unique_ptrs has to recursively free each node.
If I know that I'm going to free the tree all at once, I can allocate the nodes in a linear allocator, instead.
If the structure of the tree is going to change, ownership will always be consolidated, and I know the sizes of my nodes, I'll consider using a node pool.
I write fast runtime code though, so these things matter to me. For an application, I might just use smart pointers everywhere.

David Perry
David Perry

Okay, fine. But it still solves other issues that yours doesn't, like use-after-free.

#define free(p) ((void)(*(p) || abort(), free(p), (p) = NULL))

Anthony Perry
Anthony Perry

You would have to pass a pointer to the pointer for that to work as a function.
You're right. Sorry I'm about 3 beers deep and it's been awhile since I've looked at my impementations of xfree/xmalloc
I do know they saved me a ridiculous fucking amount of time though because I never had to bother making those boilerplate checks. Same with xstrcpy and xstrcat, because yeah C is ancient and ANSI standard but also but that just introduce some basic safety checks, these functions are absolutely not your performance bottlenecks

Robert Parker
Robert Parker

What does it matter? *NULL segfaults anyway, so what could go wrong if I don't?

Luke Jones
Luke Jones

array2 is storing how many of each value in array1 is stored. So if array1 contained 30 "12"s throughout the array,

array2[12]
would equal 30. It's doing this by incrementing the index of array2 which is the value of array1.

Ian King
Ian King

They're all fucking shit and lexers are easy you pussy
It's not about difficulty, I could easily do it if I want, I just don't want to.
I hate string processing.
It's like rubbing your dick against painfully coarse sandpaper.

Lincoln Parker
Lincoln Parker

stop abusing the comma operator

Because now you know you ran out of memory and not some mystery bug happened. malloc returns NULL when it can't allocate, and you're *supposed* to check that. Obviously nobody ever does, but if you don't and actually hit that problem then you're in for a fucking nightmare of a debug session because replicating that error is borderline impossible.

Nolan Edwards
Nolan Edwards

I hate string processing
Everybody does, it's arbitrary data translation and is forever a pain in the ass. Lexing is not. Lexing is stupidly easy. Read a string. Does this one character match a token pattern? Yes? It's that token. Does this next arbitrary length of characters match a pattern? Yes? It's that token.
No? To either? Error and crash, invalid string.

Henry Wilson
Henry Wilson

stop abusing the comma operator
So how else, genius?
Because now you know you ran out of memory and not some mystery bug happened.
fair enough
but I can still do it in a macro to avoid having to replace all malloc calls

Chase Morales
Chase Morales

he can't handle rubbing his dick against coarse sandpaper
git gud faggot

Daniel Jones
Daniel Jones

You could pattern match on (kind x) rather than x, where x is the token?

Brody Rodriguez
Brody Rodriguez

So how else, genius?
Any other way that isn't archaic and dumb
but I can still do it in a macro to avoid having to replace all malloc calls
And you can also do it with the comma operator.
You can do whatever the hell you want. But you're asking for opinions here so:
It's not 1979, you don't need to use macros anymore, you can just do function inlines, and you shouldn't be proprosing a single macro string replacement for a core memory management function in the first place.
I feel like you're trying to brilliantly solve something in a large codebase with a small macro change and I gotta tell you: Either it won't work, or it'll work for 6 years and then you'll spend 11 fucking months having to unravel it and reverse it because it caused an unintended side-effect somewhere in some part of the codebase.

Macros are not extensions of C grammar, they are inherently unsafe, do not use them. Use inlined functions, GCC and Clang are really fucking good at optimizing them to near identical levels of macro definitions except they're safe.

Anthony Jenkins
Anthony Jenkins

That would work but then I lose the other information associated with x, unless I do it when passing it into the function
But then I'm not passing a token, I'm passing the kind, and then I lose all the information about the token that isn't the kind

Basically I'm hoping there's some way I can apply pattern matching on the token without losing the rest of its data, like

func :: Token -> Kind -> a
func t (kind t) = --stuff

Hunter Carter
Hunter Carter

But I can't do what I want to do with an inlined function. My safe free is fine, with the exception of freeing an input with a side effect (oh god why)

Write an inline function that also mutates p, without requiring changes to the caller.

Sebastian Smith
Sebastian Smith

You can

func t = 
case kind t of
kind1 ... -> you can still use t, the token

Josiah Peterson
Josiah Peterson

that also mutates p
Fucking disgusting. Hidden side effects are one of the worst things you can do.
That's why I said .

If you have to put a &, it clearly states that it can be mutated.

Henry Perry
Henry Perry

jowforums.com/thread/70595085/technology
jowforums.com/thread/70595085/technology
jowforums.com/thread/70595085/technology

John Lopez
John Lopez

But I can't do what I want to do with an inlined function
That's because you want to overwrite the exiting calls to a function which is _a very fucking bad idea_
You say its fine, it looks mostly fine, but god only fucking knows what shithead did some unnecessarily obtuse thing inside a free call that your macro doesnt deal with because its a string replacement and boom you have unholy, unnecessary bugs.

Fixing safety is a long technical debt process, there is no fast speedup, any attempt at that is just more technical debt. Trust me.

Write an inline function that also mutates p, without requiring changes to the caller
A) You don't seem to understand "inline"
B) If you mean "without touching any other code" then replace every occurance of

#include <stdlib.h>
with
#include <stdlib2.h>
which is just stdlib except for malloc and free, which are now safely inlined xfree and xmalloc versions.

Tyler Nguyen
Tyler Nguyen

it's only unsafe if you're somehow selecting a format string at runtime instead of just feeding different variables into it
otherwise any c compiler in the past several decades will type-check it for you

now the C text INPUT functions, those are unsafe as hell

Carson Campbell
Carson Campbell

A functional language is not magic you ninny.

Justin Turner
Justin Turner

nobody ever checks malloc
If you're a shit dev you don't. People who shouldn't be using C are the kind who don't check their pointers. You're literally the reason software is shit.

Levi Hall
Levi Hall

most of the time the response to "oh shit i couldn't allocate because the machine has totally run out of memory" is just "well fuck we don't have any good way to recover this and continue execution, just panic and quit", which is exactly the same result as if you DON'T check malloc

Adrian Reed
Adrian Reed

Kek. GNU software aborts on malloc failure.

Gabriel Clark
Gabriel Clark

No. you'll crash elsewhere half the time. It's not common that you only allocate one of something, and since you're not checking if it's crashing then, you get a crash and you have literally no clue where it is, except it's an access violation, not even necessarily accessing null. If you have a single sanity check, a line is written to a file, or printed to the screen, or whatever, and you know exactly what the "problem" is. A failure to allocate isn't necessarily an unrecoverable situation either, so immediately crashing for a random reason is literally the second worst thing you can do, next to keep running and crash later.

Carter Morgan
Carter Morgan

jowforums.com/thread/70596661/technology
jowforums.com/thread/70596661/technology
jowforums.com/thread/70596661/technology

Disable AdBlock to view this page

Disable AdBlock to view this page

Confirm your age

This website may contain content of an adult nature. If you are under the age of 18, if such content offends you or if it is illegal to view such content in your community, please EXIT.

Enter Exit

About Privacy

We use cookies to personalize content and ads, to provide social media features and to analyze our traffic. We also share information about your use of our site with our advertising and analytics partners.

Accept Exit