4 ms·
> Want to spend 3x as much time writing code as a comparable C++ solution Coming from Python and dabbling in C for embedded software, this is the one that gets
by StavrosK 10y ago
> Want to spend 3x as much time writing code as a comparable C++ solution
Coming from Python and dabbling in C for embedded software, this is the one that gets me the most. It's so frustrating to be spending hours doing something you can do with one line of the regex library in Python...
- bkjsbkjdnf 10y agoThere are regex libraries for C. Worst argument so far.
- majewsky 10y agoI would upvote this if it weren't for the second sentence.
- ixtli 10y agoI think it's a bad thing that hacker news is so allergic to strong editorialization.
- lemmings19 10y agoI do not. There is enough of it elsewhere on the web, it's nice to be somewhere relatively free of it for a change. The conversations that occur here generally seem much more structured.
- ixtli 10y agoI agree that they are more structured, but I don't see any evidence that this is in any way due to how immediately people are attacked for wording things strongly. Engineering is a life and death business more often than people think; it deserves people who feel strongly about it. As an aside, I think the rules about trolling and personal attacks are pretty clear and easy to enforce. What I'm specifically concerned about is that those rules are evoked outside of the spirit in which they were created to attack emphasis in general. In fact, most of the discussion here is in clear violation of "Please avoid introducing classic flamewar topics unless you have something genuinely new to say about them." but obviously we rightly care a lot about this topic and, since people are acting like adults, no one needs to tap on the poster so to speak.
- lemmings19 10y agoIt looks like we agree that attacks are not helpful, but freedom of expression can be. I appreciate that the majority of people in this forum express their opinions in a highly productive manner void of animosity, as you've just demonstrated. The previous's user's remark "Worst argument so far." did not convey this spirit. Whether intentionally or not, antipathy and pure negativity do not bring out the best of people in online forums. It is my hope that those are two things which this community seeks to discourage, but not all freedom of expression. This is how I interpreted the comment which sparked your initial response.
- coldtea 10y ago>There are regex libraries for C Which everybody here knows and nobody doubted. So, a big duh! What the parent means is with Python you don't need to go and install one, adjust your makefiles, etc. Regex are right there in the standard library, and things that are not are immediately usable in just a "pip install" away.
- StavrosK 10y agoExactly. The biggest problem I have is just finding appropriate libraries. With PyPI I know where they are, how to get them and which one is popular. With C, I'm completely lost. I use PlatformIO's manager, but it's limited to embedded libraries, so I just don't know where to find things at all.
- EpicEng 10y ago...google
- Manishearth 10y agoIts not just finding the libraries, its also marrying the makefiles.
- anthk 10y agoWith Linux that's trivial to know.
- EpicEng 10y agoSure, and to get that Python requires a big runtime to be present wherever it goes. Trade-off.
- snakeanus 10y agoapt-get install Done! Do people actually use pip when you can just use the package manager of your distro?
- Nursie 10y agoI love python too. It's my favourite language for getting stuff done fast. However it doesn't give you the control or the performance of C without some serious work, some of which is usually work in C!
- bluejekyll 10y agoPython let's you get stuff done fast, but it's almost more dangerous than C in some respects. Without a compiler, you run the risk of deploying code that will not run, and you don't know until that section of code is actually executed. Requiring a massive set of tests to actually validate your code. On top of the additional testing, you also will have a performance problem at some point after success. And then people will discuss or even plan for a rewrite in a more performant, language. But we all know that rewrites usually fail to materialize. PoC's turn into products, products turn into companies, and companies bottom lines can't generally spare time and money to rewrite the entire service. I'm not advocating for C, but I wouldn't put Python up as a comparable thing.
- witty_username 10y agoHaving the correct type doesn't guarantee correctness. As a noob C programmer, in my programs segfaults often occur along with undefined behaviour (which is much worse, as your program will silently give the wrong output). While in Python, you'd get a traceback which is much easier to debug. > Requiring a massive set of tests to actually validate your code. Both require tests to validate your code. Sure, static typing can verify some trivial mistakes, but they can't check that array accesses are in bounds, integer overflow, etc.
- kruczek 10y ago> As a noob C programmer, in my programs segfaults often occur along with undefined behaviour (which is much worse, as your program will silently give the wrong output). > While in Python, you'd get a traceback which is much easier to debug. Well, C's segfault will also generate core dump, which is essentially the same thing as Python's traceback - it tells you where the program crashed.
- jackhack 10y agoI don't understand your complaint. There are mature regex libraries for C found with the obvious Google search. Source code included. Why would you not just pick and consume one, as you would in Python? Overall though I think what you may be seeing is simply the stratification of software development; what began in the 70s and 80s has come to fruition. There are different planes of existence, like thermoclines in the oceans. A developer may (and is likely to) live in one forever, without crossing above or below. Each has its purpose. While I wrote my own database and rendering engines in the 80s as part of applications development, I wouldn't dream of it today unless there was a very, very good reason. Same goes for network stacks. Or math libraries. Memory managers. Etc. Sure, coming from the Python ecosystem, you will feel as though there is a shortage of auto-pilot-like assistance, but you must realize you are in a very different world now - Embedded work is (frequently) focused on predictability, responsiveness, efficiency, and even moreso with realtime work. You are the engineer in charge, and all the safe boundaries and cushions of the interpreted language world are now missing. Want to REALLY feel naked? Drop down to assembly on any platform and try to emit a simple "hello world." For those who have never done so, it's a humbling experience but rewarding. Remember that C was designed as a "universal assembly language", easily portable to different architectures and close (enough) to the metal so the programmer can have full control over the machine. Best analogy I've heard: C is like a chainsaw - used carelessly one can cause enormous damage and destruction, but in the hands of a skilled/experienced craftsman, very clever solutions are possible.
- StavrosK 10y ago> I don't understand your complaint. There are mature regex libraries for C found with the obvious Google search. Source code included. Why would you not just pick and consume one, as you would in Python? Mostly because I'm used to one single place for libraries (PyPI) and I don't know how to find (and evaluate) libraries in C. I also don't know if they'll run on my MCU or how much RAM they require. I have found one or two embedded regex libraries, but they were very limited in what they could do or failed some other criterion. Besides, that was just an example, it's just death by a thousand cuts with similar things one after the other.
- 10y ago
- protomok 10y agoAn alternative to the suggestion to use a regex C library is to embed Lua code into your C code. Lua+C is great for resource constrained embedded systems and can make text parsing a lot less painful than using pure C. The Lua docs provide some examples of integrating Lua into C here - https://www.lua.org/pil/24.1.html https://www.lua.org/pil/24.1.html.
- StavrosK 10y agoThe problem there is that usually you're constrained to 2 kb of RAM or so for an Arduino, so that's too heavyweight :/ Plus, it's outside my abilities currently, sadly.
- krylon 10y ago> Plus, it's outside my abilities currently, sadly. If your target only has two KB of RAM, Lua is a no-go, I guess. But skill-wise, I can highly recommend it. The reference manual is very well-written, the Lua language itself is very nice and easy to learn, and Lua's C interface is very pleasant to use; and again: the documentation is very good. (Also, the community is very friendly!) If you ever take a shot at it, the Lua Users Wiki (http://lua-users.org/wiki/ http://lua-users.org/wiki/) is a good starting point.
- StavrosK 10y agoHmm, the example you posted doesn't actually look very complicated at all! And I agree, Lua is a very nice language, I've used it for other projects.
- ArkyBeagle 10y agoPerhaps because I've done it all my adult life, I've never understood how text manipulation in 'C' is all that painful.
- Grishnakh 10y agoThis is why (depending on exactly where in the stack you're working, and on what kind of device; I'm assuming you're developing a graphical application on an embedded device with an ARM-like CPU and a small screen for this example) you should be using Qt Embedded. It's C++, and has a very good regex library. You get the power and speed of C++ and all kinds of nice features like regexes.
- ArkyBeagle 10y agoIt's (nearly) trivial to write FSM in 'C' that do what regexp do in Python.
- kps 10y agoYes, if you're matching constant regular expressions on an embedded device using a general-purpose runtime regular expression processor, you're probably Doing It Wrong™.
- EpicEng 10y agoSure, but you're giving up control. There's a trade-off and there is a whole world of things which simply aren't practice to do in Python, but work just fine in C.