#something that parse a file?

65 messages · Page 1 of 1 (latest)

lament notch
#

rate 0 to 10 for 1 month on c++?

gilded nimbus
#

10/10 for no using namespace std

lament notch
#

pls i want actual feedback

#

things i could do to do better code

gilded nimbus
#

i think you could have less nested loops

lament notch
#

ik

gilded nimbus
#

if (File) is not the best way to check if a file is opened correctly iirc

valid phoenix
# lament notch rate 0 to 10 for 1 month on c++?

What is "1 month"?

Like, the answer we give you can vary from incredibly good to horseshit depending on it.
E.g. if by "1 month" you mean that you started 30 days ago and did 1 hour per week, and had no prior experience, then this is a 10/10.
If by "1 month" you mean that you now have 30 * 24 = 720 hours actively working with C++ and you were already familiar with programming and tons of other, similar languages, then this is a 1/10.

lament notch
gilded nimbus
lament notch
gilded nimbus
lament notch
surreal galleon
gilded nimbus
valid phoenix
lament notch
#

idk why

valid phoenix
#

C functions

#

!man toupper

untold zealotBOT
#

toupper, tolower, toupper_l, tolower_l - convert uppercase or lowercase

Synopsis
#include <ctype.h>

int toupper(int c);
int tolower(int c);

int toupper_l(int c, locale_t locale);
int tolower_l(int c, locale_t locale);

Feature Test Macro Requirements for glibc (see feature_test_macros(7)):

toupper_l(), tolower_l():
    Since glibc 2.10:
        _XOPEN_SOURCE >= 700

... (truncated)

lament notch
#

i though it was native form c++

gilded nimbus
#

yep, C++ headers usually include C headers

lament notch
#

oh so C stuff doesnt contain the std namespace?

valid phoenix
#

Well, C doesn't have such a thing as namespaces

lament notch
#

to check just for endoffile flag since i already know file is opened

surreal galleon
lament notch
#

ok

#

so File everywhere

#

just check the object

#

or File.good() as equivalent

gilded nimbus
#

consider making your own tolower function which is a constexpr lookup table >:)

surreal galleon
# lament notch <:nooo:893467357148753920>

This, to me, feels very stream-of-conciousness writing (i.e. adding cases one after another), which often happens in first revisions, you can try pulling out reused code, and it should likely become significantly more readable (or try rewriting it again using some of the things you learned from this revision

lament notch
#

how would you do it?

#

using find() member function might be better

#

way better

tawny shuttle
#

You just uploaded the files here and not to, like, github. -1 point

Everything is in main(). No helper functions or classes. -1 point

And you didn't even specify what the program is exactly supposed to do. And it isn't very clear from the code either. -1 point

lament notch
#

noted

#

im learning about functions

lament notch
tawny shuttle
#

I don't like this style of error handling:

if(everything ok){
  do_stuff
} else {
  error!!!
}

This creates a lot of nested ifs

I prefer:

if(something wrong){
  error!!!!
  exit program
}
do_stuff..
lament notch
#

basically while parsing through "[jhaduga]" i set IsSection bool to true

#

so all char parsed within [] are asigned to a string

#

i think thats way cleaner and prob how parsing is done

#

@surreal galleon

#

so i just only have a main loop to parse all file and just a lot of ifs to do the asigment control

#

no nested loops are required

valid phoenix
surreal galleon
# lament notch <@536702784326729728>

I would do a significantly different approach instead of character-by-character, the file format lends itself more to:

if(File.good() && File.peek() == '[')
  sectionName = readUntil(']');
else
  data = readData();
lament notch
#

yeah that also could work

surreal galleon
#

Also, "real parsing" is usually done with recursive descent parsers and other more high-level algorithms, which aren't really necessary here; Or they are done with Flex + Bison, which generate recursive descent and other parser families, though as with a self-implemented recursive descent parser, this is overkill in this application

lament notch
#

what do you mean by recursive descent parseing?

surreal galleon
# lament notch what do you mean by recursive descent parseing?

It's a type of algorithm for parsing context-free-grammars: https://en.wikipedia.org/wiki/Recursive_descent_parser (A high-level overview from Wikipedia)

In computer science, a recursive descent parser is a kind of top-down parser built from a set of mutually recursive procedures (or a non-recursive equivalent) where each such procedure implements one of the nonterminals of the grammar. Thus the structure of the resulting program closely mirrors that of the grammar it recognizes.
A predictive par...

#

Though if you don't know automata theory it's a real rabbit hole, so the TL;DR is that it's overkill for this application

lament notch
#

indeed

#

anyways ty for the feedback

#

i want to improve my algorithmic skills and basically "thinking", i know best way is just to code and keep coding

#

im all ears to advises

surreal galleon
# lament notch im all ears to advises

I would say don't worry about time complexity and parsing just yet, since these are higher-level concepts that don't make sense without a solid foundation in CS theory, the best advice (IMO) is to try and write reusable code in functions, and try to see patterns in what you're writing (and if you look in projects what they're doing), and then look into books/classes on Data Structures+Algorithms and other CS theory concepts

lament notch
#

i coded it like that becouse i was never introduced to functions