|
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. |
On December 05 2019 17:27 zatic wrote: I feel like a first year programmer ... Was stuck for almost 2 days because I had a whitespace trailing a URL I had to compute a hash on. Spent two days trying to find the error in my implementation of building the string to hash or the hashing function because the resulting hashes just would not match. And of course the software I am working with only has a console for debugging where I just couldn't see the stupid whitespace at the end of the URL.
Well, long time ago I've learned to do 2 things: 1. Set my editor/IDE to strip all trailing whitespace and EOF newlines on save. 2. Always strip whitespace from the beginning and end of any strings that enter the system from the outside.
This has saved me a lot of headaches.
|
Zurich15234 Posts
Yeah this probably wouldn't have happened had I used my own tools. But this was done on a black box system where I just have an in-browser editor to write the code.
|
On December 05 2019 17:27 zatic wrote: I feel like a first year programmer ... Was stuck for almost 2 days because I had a whitespace trailing a URL I had to compute a hash on. Spent two days trying to find the error in my implementation of building the string to hash or the hashing function because the resulting hashes just would not match. And of course the software I am working with only has a console for debugging where I just couldn't see the stupid whitespace at the end of the URL.
Hihi, always fun. I spent a whole day on a simple bug once before realising I had put a > instead of < in a simple for-loop. Sometimes the brain just short-circuits and you start looking in all the wrong places before checking the basics.
To be fair, catching trailing white spaces in a console debugger is next to impossible if you don't know to look specifically for it. I doubt I'd catch that one any quicker either.
|
In this situation i usually prefere to take a break and claer my mind. Just this week i spent over 1 hour "banging my head into the wall" and couldnt find the source of some weird behavior. I went to eat lunch and after i came back i found source of the problem in under 1 minut. My eyes/mind were omiting the fact that i am converting to string something i shouldnt. And i wouldnt notice it until i took a break.
|
On December 06 2019 20:11 Silvanel wrote: In this situation i usually prefere to take a break and claer my mind. Just this week i spent over 1 hour "banging my head into the wall" and couldnt find the source of some weird behavior. I went to eat lunch and after i came back i found source of the problem in under 1 minut. My eyes/mind were omiting the fact that i am converting to string something i shouldnt. And i wouldnt notice it until i took a break.
I swear 80% of my problem solving happens in the bathroom
|
I am having a really weird problem with a uni assignment in c++(well technically not the actual assignment, rather my attempts to do a bit more than what is asked). I am reading in a file and do somethingwith the data but out of curiosity I wanted to start working with the data before the reading in is completed since the reading takes a bit of time in which a bunch of cores do nothing but twist their thumbs. For some reason though, unless I wait about a second after the reading thread has started, I get a Segmentation fault.
the graySortRecord class was provided by my prof and is this: + Show Spoiler + class graySortRecord { public: static const int record_size = 100; static const int key_size = 10; private: char data[ record_size ]; public: // Constructors graySortRecord( ) = default; // simply copy the only member, data graySortRecord( const graySortRecord &other ) = default; // simple. // Destructor ~graySortRecord() = default; // read only, "safe" getter for the data field // unsigned char *data( ) const { return data; } // overloaded "less than" operator bool operator <(const graySortRecord& rhs) // rhs = right hand side { return ( memcmp( data, rhs.data, key_size ) < 0 ); }
// overloaded input friend std::istream& operator>>( std::istream& in, graySortRecord &rec ) { return in.read( rec.data, graySortRecord::record_size ); } // overloaded output friend std::ostream& operator<<( std::ostream& out, const graySortRecord& rec ) { return out.write( rec.data, graySortRecord::record_size ); } };
my read looks like this(running as a single thread): + Show Spoiler + void readFile(std::string fileName) { std::ifstream inStream(fileName, std::ios::in | std::ios::binary); if (!inStream.is_open()) { std::cerr << "ERROR: Could not open input file named " << fileName << std::endl; exit(-2); }
graySortRecord newRecord; long int numRecords = 0; while (inStream >> newRecord) { mutexRecords.lock(); records.push_back(newRecord); mutexRecords.unlock(); } fileReadingDone = true; }
workerthread function, the code during which the segvault happens. each thread has its own set of data that doesnt get touched by the other threads. + Show Spoiler + mutexRecords.lock(); if (readingHead < records.size()) { //get stuff myRecord = &records[readingPos];//take record to do something later on readingPos++; mutexRecords.unlock();
// overloaded "less than" operator // bool operator <(const graySortRecord& rhs) // rhs = right hand side // { return ( memcmp( data, rhs.data, key_size ) < 0 ); } // gets called here resulting in a segvault because the rhs.data[] is only declared but no actual values }else{ mutexRecords.unlock(); /use idle time for some stuff}
The weird part is I did some dummy debugging with couts and confirmed that readingPos is way behind the number of elements in my records vector. Plus the mutex together with the readingPos should guarantee that I interact with my data safely. My current assumption is that the overloaded input of graysortRecord doesnt work like I think it does. My assumption is that it dumps that binary data raw into the memory that has been allocated for a graysort record, giving me back a ready to use graySortRecord but because of the weird segvaults I think this might not be the case? This would mean the mutex in my read function no longer guarantees that there are only finished graySortRecords in my vector of records.
I have some doubts regarding this ssumption though since: - the segfault happens despite the readingPos behin way behind the filereader, so its not that we fail to work with the most recent object - I can run this with more threads, and will even end up having stuff happening in the idle block of my worker threads aka they went through all the data thats present atm with the filereader still not finished reading everything without a segvault so for some reason all the graySortRecords are fine as long as I wait a second before I start working on the set???
|
|
Zurich15234 Posts
On December 05 2019 21:17 zatic wrote: Yeah this probably wouldn't have happened had I used my own tools. But this was done on a black box system where I just have an in-browser editor to write the code. At least it's good to know that it happens to the best of us. https://twitter.com/karpathy/status/1203802860825108480?s=19
|
|
On December 09 2019 23:51 Nesserev wrote:
Are you storing the addresses of a vector's elements in your worker threads, while at the same time, you are also pushing new elements at the back of the vector?
Vectors have two "sizes": the current size (how many elements does it currently hold?), and their capacity (how many can it hold?). If a vector's size exceeds its capacity, then room is made for new elements by allocating a new larger block of memory, and the vector's data is copied to this new larger block of memory. This means that if you store the addresses of a vector's elements, and one of these resizings happens, then the stored addresses will still point towards the old block of memory that has been deallocated.
A quick fix would be to reserve enough memory beforehand for the vector by using std::vector.reserve(n) method, where n is a ridiculously large amount of elements, large enough to handle any task realistically thrown your way. This would also explain why you do not get the segmentation fault when you wait long enough first; because then your vector's capacity would already be large enough to hold all the records.
A (better) solution would be not to store the addresses of a vector's elements, if that's possible. (: Thanks so much, I am not sure if this is the cause of the problem, but it sounds very likely. I mostly chose a vector because of cache efficiency since I have to iterate through it but the more I think about it thats not all that beneficial in my case. Guess a list-like structure will do
|
Netherlands45349 Posts
This might be perhaps an odd question, I am dipping my toe into learning a bit of programming (mostly frontend) to assist with my daily works (I work in online marketing and as such JS, HTML & CSS can be quite useful, if only to communicate with development properly).
I commute quite a bit, I was wondering what if any resources I could consume that are mobile friendly, that includes stuff such as coding "apps" that I can just do bitesized on the road. I know its better to do stuff on desktop but you know, I might as well spend time commuting a bit useful.
|
On December 23 2019 01:29 Kipsate wrote: This might be perhaps an odd question, I am dipping my toe into learning a bit of programming (mostly frontend) to assist with my daily works (I work in online marketing and as such JS, HTML & CSS can be quite useful, if only to communicate with development properly).
I commute quite a bit, I was wondering what if any resources I could consume that are mobile friendly, that includes stuff such as coding "apps" that I can just do bitesized on the road. I know its better to do stuff on desktop but you know, I might as well spend time commuting a bit useful. Depends how basic your knowledge is. There's some games to teach you computational thinking that I know of. One I kinda liked is lightbot. If that's what you need, you can give it a try. Other than that, there's online resources that you can do we, but I'd limit it to passive stuff then, because actually writing code on a phone is a nightmare.
|
Netherlands45349 Posts
Passive stuff is fine, I don't need to/want to write code on a phone, I think perhaps getting more theory would be good too, as sometimes I feel like I am executing more stuff and not thinking enough about the thought process behind some code.
In a way I suppose books could work too? But I am a bit war as I feel like programming would be stuff where things change too fast and become outdated?
|
On December 23 2019 07:16 Kipsate wrote: Passive stuff is fine, I don't need to/want to write code on a phone, I think perhaps getting more theory would be good too, as sometimes I feel like I am executing more stuff and not thinking enough about the thought process behind some code.
In a way I suppose books could work too? But I am a bit war as I feel like programming would be stuff where things change too fast and become outdated?
You can always read up on stuff that's quite universal. Different ways of managing programming projects (agile for example) and theory that is applicable to many programming languages and is considered to be quite the standard for working with code.
Some examples: Clean Code The Pragmatic Programmer Design Patterns Code Complete GOOS
I think that anyone interested in programming should read those books (all of them).
|
On December 23 2019 14:29 Manit0u wrote:Show nested quote +On December 23 2019 07:16 Kipsate wrote: Passive stuff is fine, I don't need to/want to write code on a phone, I think perhaps getting more theory would be good too, as sometimes I feel like I am executing more stuff and not thinking enough about the thought process behind some code.
In a way I suppose books could work too? But I am a bit war as I feel like programming would be stuff where things change too fast and become outdated? You can always read up on stuff that's quite universal. Different ways of managing programming projects (agile for example) and theory that is applicable to many programming languages and is considered to be quite the standard for working with code. Some examples: Clean CodeThe Pragmatic ProgrammerDesign PatternsCode CompleteGOOSI think that anyone interested in programming should read those books (all of them). This. Also a decent intro to algorithms and data structures. I wouldn't deep dive straight into Knuth, but knowing the difference between a linked list and an array is never going to be redundant knowledge.
I've never read it, but seen it mentioned a few times as a good intro: https://www.amazon.com/Grokking-Algorithms-illustrated-programmers-curious/dp/1617292230/?tag=javamysqlanta-20
There are also various introductory courses on Coursera or other MOOC platforms, and of course an infinity of YouTube resources for introductions to programming in any language you can imagine.
For front end web programming specifically, it's worthwhile (essential) to go through w3school's tutorials and explanations. But they are very specific, so it's best to know what you're looking for first.
|
Given your goals I would suggest just using resource buffet style - only take what you need. Don't read a book end to end.
If you're sticking to front end you don't need Algorithms and Data Structures enough to justify the effort.
Clean Code is good whether you are front or backend, though you should only need the first few chapters IIRC. I've heard the Pragmatic Programmer is good. I wouldn't bother with Design Patterns.
Personally, I think the frameworks and libraries popular nowadays have great open source documentation. If you're currently trying to build a site then it can be useful to look up stuff that's been bothering you on the commute in to expand your knowledge. If you're not currently trying to build a site you should be.
|
Does anyone here know how to make a graph of a Database where the tables are connected by selects, joins, etc. rather than Foreign Keys? It seems like database graphing technology assumes you have key linked tables. For context I am using SQL Server. This would be used to debug/trace data flow in the DB between tables.
|
Netherlands45349 Posts
Thanks for the help, yes my first project will be to build my own site, seems fun so far but quite overwhelming.
|
On December 24 2019 02:13 WarSame wrote: Does anyone here know how to make a graph of a Database where the tables are connected by selects, joins, etc. rather than Foreign Keys? It seems like database graphing technology assumes you have key linked tables. For context I am using SQL Server. This would be used to debug/trace data flow in the DB between tables.
Well, relational DB's are kind of designed to work with FKs although there are instances where you don't use them, but that's usually due to performance issues. Using selects and joins instead of foreign keys seems like really bad idea when it comes to performance.
Speaking of such graphs, isn't it basically like creating a graph of a view (materialized or not)? Because that's what you get.
http://www.postgresqltutorial.com/managing-postgresql-views/
|
On December 24 2019 02:11 WarSame wrote: Given your goals I would suggest just using resource buffet style - only take what you need. Don't read a book end to end.
If you're sticking to front end you don't need Algorithms and Data Structures enough to justify the effort.
Clean Code is good whether you are front or backend, though you should only need the first few chapters IIRC. I've heard the Pragmatic Programmer is good. I wouldn't bother with Design Patterns.
Personally, I think the frameworks and libraries popular nowadays have great open source documentation. If you're currently trying to build a site then it can be useful to look up stuff that's been bothering you on the commute in to expand your knowledge. If you're not currently trying to build a site you should be. Eh. An introduction to programming should include, imho, some basics in data structures and algorithms, even if you're just using libraries. Treating libraries as magical black boxes can really screw you over, and it's good to be able to recognize where you might not be able to do so, or how to refactor code to work better with your library suite.
As for design patterns, they aren't all important for front end design, but understanding MVC, client-server, chain-of-responsibility, observer, and for JavaScript specifically, promises are kinda essential (and in general some knowledge of ways to deal with asynchronous distributed computing).
As for web programming in general, it's very important to have a solid understanding of the architecture and HTTP. It's the most common mistake in my students' work that they don't properly understand the concept of how backend and frontend work together to generate a web resource and how HTTP fits into the workflow. A lot of it is hidden away in whatever framework you end up using, but that doesn't mean it won't break if you don't understand the basics of what you're doing.
|
|
|
|