Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Search - "structs"
-
This morning finally pointers to structs in C finally clicked on my mind!!!🤯
80% of the C code that puzzled me now makes sense!! 🤗12 -
When you create a bunch of objects in Java and it crashes because you're used to the memory usage of C's structs.3
-
Oh man where to start:
Not wanting to use LINQ because he did not wanted to "download external dependencies"
Not wanting to use prepared statements on their php sql code, and refusing to use pdo because they will "always use mysql"(moved to postgreSQL shortly after I left)
For some reason including a php file that only had ?>......thats it....only ?>
Use c++ but refused to learn oop and use structs for everything, importing stdio.h and printf everything.....like really?
Maybe just nitpicking, but refusing to use the recyclerview pattern on am android app. The implementation was faster after I made the change.
Importing a library for promises instead of using the ones already in the language(JS)
Changing the style of aaaaall p tags instead of using classes as well as refusing to use divs in place of p tags...well...fuck
Not indent his ASP classic code
Use notepad on his asp classic code
Use ASP Classic in 2017, even for new projects6 -
So I wanted to spread a struct in another struct to fill fields with the value `None`. Not what I expected when I googled "Rust spread into"..9
-
When I started programming ~5 years ago.
Teacher: OK, C++ classes and structs have 3 access modifiers: private, public and protected.
Private fields can't be accessed out of the current class.
Me thinking: wow, that's cool, but how can it be? I have to research.
I went to home and wrote a class with one variable with its set and get functionality.
Then I opened Cheat engine) and tried to access and change the variable. When I succeeded, I started hating this world of programming.
After some time I understood that it's wonderful cause it's up to you.5 -
My first task in my current company, a few years ago.
I had to add features to a 10 year old microcontroller-based device written in C.
There was a struct named "global", which held hundreds of other structs that held variables or even more structs.
If one would have printed the structure of this mess it would haven needed several pages.
This "global"-struct was used in every single sourcefile to store and pass data around. Obviously there was no documentation and often useless comments.
Additionally there were a few protocol stacks involved, mainly similar, only differing in one or two protocol layers.
The implementation of the protocol stack was by setting flags in the "global"-struct in every protocol layer and having the application data in a buffer.
The complete telegram with all layer specific data (header, checksums, etc.) was then build at one single point right before sending it, based on the flags and the data buffer.
As there was no chance to reuse protocol layers with this implemenation. Three protocol implementations with special telegram builder existed in parallel, although they were nearly identical.
I needed a fourth variant of the protocol stack, so I had no chance but to make another copy with some minor changes.
But there was a benefit from this task.
As I had to do the software for the successor of this device from scratch I learned for many things how not to do them :-) -
teach meta language concepts: what is an operator, literal, constant, statment, control flow. the recursive nature of staments. then go into objects/methods vs structs/procedures. then teach some java. then go into reflection concepts. then use reflection for something simple. then teach a bit of perl. then let them build something in python. Anyone who can pass through that will know how to Program in whatever you give him/her.
I wish my teachers talked about the meta programing, instead on focusing on the minutia. -
I'm literally laughing my ass off at how Google gave their fat middle finger to Object Oriented programming with Go's Structs, Methods, and Interfaces. F*** you Java and C++! :-P4
-
I really am not a fan of the contortions you have to go through in Golang to deserialize a fucking JSON blob. If this were any other language I would have already had a data structure I could query rather than wasting hours twiddling structs that will be filled properly.7
-
What do you think about class-based OOP vs. Prototype-based OOP?
I think that class-based OOP is an unnecessary abstraction of structs, functions and global variables most of the time.16 -
Feeling kinda ashamed.. I couldn't implement a graph in python using classes without resorting to a library.
Wanted to test my skills but I guess I'm not quite to that level yet :/2 -
Working with a SOAP endpoint. I know it is some .NET server due to the style of stacktrace on exceptions. Nice, a framework where I can expect some type safety granted by static types. I build some xsl to transform the SOAP wsdl files into classes and structs to interact with the endpoint. Works out perfectly.
Plottwist!
Elements which are defined in the xsd/wsdl with maxOccur=unbounded and minOccur=0 should represent a simple collection of this type. Therefore does my implementation expect a collection of this type. But no. The shipped SOAP client in my stack ignores the definition and simply deserializes the SOAP response into T and not a collection of T.
Where the duck are the types when they are defined all over the place?2 -
So I have never done 'real' development on anything bar my current game engine Virgil, however found myself referring to C documentation for GLib and SDL2 rather than valadoc documentation.
Decided fuck it, I'm already converting everything to Vala's pointer syntax so I can have manual memory control, implementing stb_image and contemplating reworking SDL2_image into raw C so I'm not depending on extra libraries... Why do all this when I can just learn C and have more control.
Everything was going well and decided to buy the C programming language book, already knew about pointers and structs but ohhhhhhhhhhhhhhhhhhhh boi was I not ready for malloc .-.7 -
First round of grading the newbies' C hand-ins. Some are decent, some are great, some are way beyond the scope of the curriculum (50 line solution using structs for something that can be done in 5 lines), and some are "oh god why?".
Life as a TA is hard. -
Swift is such a horrible language now that I am actually using it. You have protocols that don't behave like interfaces, classes that aren't objects, structs that aren't passed by reference. And stupid counterintuitive generic grammer. I feel scammed.1
-
I am overwhelmed in my mind right now and I kinda just need it out.
I'm incredibly divided. There's so much I want to do which is fine I can balance some of it kinda well but when it comes to the programming aspects of what I want to do is where my head gets tugged in multiple directions.
Parts of me really want to continue to dive into C# and learn it a lot more than I currently do so I can continue to write the tools I use for problems I come across.
And the other part of me just wants to go do lower level development with C because that's where most of my goals are being mostly embedded and OS development.
But so many people I know that are incredibly smart devs use C# and I see why it's an incredible language and I'm glad it's one of the languages I know but I feel like there's so much to learn about it and I there's so much shit I see that I'm just like I don't know when I would want to use this, or I can see X feature being very useful but I don't know where I'd use it in my projects. Hell even C#s version of structs I know are very useful but I'm not able to make good use of them
I'm just in that headspace where I'm not learning enough and I feel dumb when I look at someone else's project because there's a lot more complexity In their project that none of my projects have ever had and so many people make use of language features I've never used or thought about using (generics being a good example) and I'm constantly asking questions which I know is okay but too much is happening in life lately and it's just making it harder to handle.
Thanks to anyone that got through it hopefully I'm not alone in these feelings2 -
Note: I have deleted my previous version of this question as I found it lacking crucial information and therefore being prone to misunderstandings.
Question : In C/C++ you can position the keyword 'const' either left or right of the left-most type specifier. Which variant do you prefer?
I ask that because I'd like to hear your opinion. Although I have been working with C over three decades now, I only learned this a couple of years ago. After some experimentation I decided for myself, that I like the placement to the right more. Although the positioning to the left is taught in literally every book and course, the original placement suits me better.
One reason, of many, is the listing of many member variables in structs or classes. To have them nicely aligned, I always had to put 'const' either on the previous line or put in extra indention to everything non-const. That was quite irritating sometimes.
Another, and my main reason is, that when reading from right to left, the rhs variant just makes more sense than the lhs variant. Reading from left to right almost never makes much sense without straining your eyes. But that is, of course, highly subjective.
This is even more so if you have pointers. The 'const' keyword modifies the type identifier(s) to the left. So if the 'const' is (anywhere) left of the '*', the data is const. If the 'const' is right of the '*', the pointer address itself is const. The same applies to references.
Examples, read right-to-left:
int* const i; // i is a const pointer to int data
int const* i; // i is a pointer to const int data
int const* const obj; // i is a const pointer to const int data
The "classical" or "taught" way, that is found almost everywhere would read, still right-to-left:
int* const i; // i is a const pointer to int data
const int* i; // i is a pointer to int data const
const int* const obj; // i is a const pointer to int data const
Not only that the second "lhs" form reads worse, it also looks worse. In my opinion, the first "rhs" variant makes it simpler to quickly determine that we are dealing with three ints, while on the second "lhs" variant, one has to first get past the 'const' keywords.
I know that this is not only a matter of taste, but of course of agreement, too. You can not just go and switch the 'const' placement in long standing projects. That would surely piss of a lot of people. Or even cost you your job.
But I like to know what you people think and why.
Thanks a lot in advance!5 -
Crypto. I've seen some horrible RC4 thrown around and heard of 3DES also being used, but luckily didn't lay my eyes upon it.
Now to my current crypto adventure.
Rule no.1: Never roll your own crypto.
They said.
So let's encrypt a file for upload. OK, there doesn't seem to be a clear standard, but ya'know combine asymmetric cipher to crypt the key with a symmetric. Should be easy. Take RSA and whatnot from some libraries. But let's obfuscate it a bit so nobody can reuse it. - Until today I thought the crypto was alright, but then there was something off. On two layers there were added hashes, timestamps or length fields, which enlarges the data to encrypt. Now it doesn't add up any more: Through padding and hash verification RSA from OpenSSL throws an error, because the data is too long (about 240 bytes possible, but 264 pumped in). Probably the lib used just didn't notify, silently truncating stuff or resorting to other means. Still investigation needed. - but apart from that: why the fuck add own hash verification, with weak non-cryptographic hashes(!) if the chosen RSA variant already has that with SHA-256. Why this sick generation of key material with some md5 artistic stunts - is there no cryptographically safe random source on Windows? Why directly pump some structs (with no padding and magic numbers) into the file? Just so it's a bit more fucked up?
Thanks, that worked.3 -
Am I the only one that doesn't think purely data-oriented programming is a particularly good idea?
I mean we're throwing out all the principles that have been established over the last 20 years of OOP like encapsulation and implementation hiding. And you can say what you want about OOP and yes it's not perfect, but there are things that work quite well. Implementation hiding is a perfect example of something that I don't think I just want to give up.
DOP feels like going back to programming C in the 80's with fully procedural functions and completely open structs.
Am I just going mad?6 -
Aka... How NOT to design a build system.
I must say that the winning award in that category goes without any question to SBT.
SBT is like trying to use a claymore mine to put some nails in a wall. It most likely will work somehow, but the collateral damage is extensive.
If you ask what build tool would possibly do this... It was probably SBT. Rant applies in general, but my arch nemesis is definitely SBT.
Let's start with the simplest thing: The data format you use to store.
Well. Data format. So use sth that can represent data or settings. Do *not* use a programming language, as this can neither be parsed / modified without an foreign interface or using the programming language itself...
Which is painful as fuck for automatisation, scripting and thus CI/CD.
Most important regarding the data format - keep it simple and stupid, yet precise and clean. Do not try to e.g. implement complex types - pain without gain. Plain old objects / structs, arrays, primitive types, simple as that.
No (severely) nested types, no lazy evaluation, just keep it as simple as possible. Build tools are complex enough, no need to feed the nightmare.
Data formats *must* have btw a proper encoding, looking at you Mr. XML. It should be standardized, so no crazy mfucking shit eating dev gets the idea to use whatever encoding they like.
Workflows. You know, things like
- update dependency
- compile stuff
- test run
- ...
Keep. Them. Simple.
Especially regarding settings and multiprojects.
http://lihaoyi.com/post/...
If you want to know how to absolutely never ever do it.
Again - keep. it. simple.
Make stuff configurable, allow the CLI tool used for building to pass this configuration in / allow setting of env variables. As simple as that.
Allow project settings - e.g. like repositories - to be set globally vs project wide.
Not simple are those tools who have...
- more knobs than documentation
- more layers than a wedding cake
- inheritance / merging of settings :(
- CLI and ENV have different names.
- CLI and ENV use different quoting
...
Which brings me to the CLI.
If your build tool has no CLI, it sucks. It just sucks. No discussion. It sucks, hmkay?
If your build tool has a CLI, but...
- it uses undocumented exit codes
- requires absurd or non-quoting (e.g. cannot parse quoted string)
- has unconfigurable logging
- output doesn't allow parsing
- CLI cannot be used for automatisation
It sucks, too... Again, no discussion.
Last point: Plugins and versioning.
I love plugins. And versioning.
Plugins can be a good choice to extend stuff, to scratch some specific itches.
Plugins are NOT an excuse to say: hey, we don't integrate any features or offer plugins by ourselves, go implement your own plugins for that.
That's just absurd.
(precondition: feature makes sense, like e.g. listing dependencies, checking for updates, etc - stuff that most likely anyone wants)
Versioning. Well. Here goes number one award to Node with it's broken concept of just installing multiple versions for the fuck of it.
Another award goes to tools without a locking file.
Another award goes to tools who do not support version ranges.
Yet another award goes to tools who do not support private repositories / mirrors via global configuration - makes fun bombing public mirrors to check for new versions available and getting rate limited to death.
In case someone has read so far and wonders why this rant came to be...
I've implemented a sort of on premise bot for updating dependencies for multiple build tools.
Won't be open sourced, as it is company property - but let me tell ya... Pain and pain are two different things. That was beyond pain.
That was getting your skin peeled off while being set on fire pain.
-.-5 -
After getting fed up of “being productive” I fooled around on GitHub and had a look at the Stuxnet virus source code which was obtained using a decompiler. Experts who reverse-engineered it found out that it was written in “object-oriented C.” While C is not an object oriented language, anything you can do with classes you can do with structs, static functions, pointers & function pointers. You can see this coding style in the Linux kernel, CPython interpreter and many other places. That was the first indication that a government agency or defence industry was responsible. Amazing stuff !6
-
Never used Emacs in batch mode, did it today to transform some code generated by struct2ts (convert Golang structs to Typescript classes/interfaces).
I won't rely on sed/awk for complex stuff ever again, is much pain in the ass for me tbh.4 -
I'm starting on C# and some of the lesson plans out there dont make sense. So far Bob Tabor and Plural Sight has helped me half way and the bulgarian shark book too. What has helped you cross that threshold past the basics. I'm stuck on structs, namespaces, sort algorithms, sql and json.6
-
Which encryption library do you people use with c/c++? I'm trying to use openssl but well there is more documentation about how to replace my own heart in the dark than on that. Also most of the structs have missing declarations hell yeah its nice to have a EVP_PKEY but what's that? Oh I know it's a evp_pkey_t and what's that? Nothing apparently. Comments? You kidding??? A proper library doesn't have them...3
-
ok I think a lot of my frustrations in rust stemmed from assuming struts are like objects and therefore can contain conceptually similar things in them that in your head would seem like the same "object", and that methods should be derived therefore and such
but in reality in rust struts are for conforming to borrowing rules and it doesn't care about your conceptual organization I guess. if you try to organize things like the structs as objects then you get borrowing issues on some occasions and then I would get stuck trying to figure out how to put a method on a struct when I need to drop borrowing to do some task and whatever
the solution is to throw out your human notions of organization
so I guess it's more bare-bones to how the machine thinks about stuff (well how the borrowing is coded in the language) and doesn't care how a human does (like notions like object orientated design)
this is odd to me in a modern language but at least I've crawled out of my brain damage with enough drug-use now that I can have such epiphanies I guess. I feel so slow. I swear this should've been massively obvious and easy to grasp in like a few days before for me. rip
instead it was 2-3 years of ~5 months of actually deep coding 😒
also I can blame people saying rust can do everything, like that you can do object orientated design in it. they're being dishonest and it's harmful to the learning process if you're acting like that 😩. stop being a cult, you'll literally be more popular4 -
Addition to
https://devrant.com/rants/2227936/...
So my programming teacher knows his shit, but is pretty bad at explaining it.
I can already see some of the other students, especially the ones without prior programming-experience, flunking this class.
Today spent most of the class talking about 2-complement and the functions in math.h.
I think we didn't even learn about reusing code with functions, or structs.
I use some of my time, helping the other students getting through this somehow.3 -
I couldn't find a program for this so I'm making one. Cli based. Have a json object you need to unmarshal in golang? Yeah I was getting tired AF making structs for all of them with the json tag name over and over, so I'm mid way through a python script that generates the structs for you. I'll link it here when I'm done.
And if you're wondering why python? Dynamic object definitions. That's why it's trouble in go in the first place.3 -
Okay, so I had an object consisting of tables (basically classes) and structs (classes with only scalars as their properties).
I was about to serialize the object with vectors of classes and structs and wrote some nice tests for it wondering why they fail to validate the data after deserialization and why I only got garbage for the vectors of structs whilst the tables worked just fine.
Turns out there is an undocumented function called CreateVectorOfStructs which shall be used for structs instead of the regular CreateVector ...
There go three hours of blaming memory issues and running Valgrind over and over again ...