To add to #1, Follow phpdoc
To add to #2, I would say PSR 2 is a good way to go, and it can be autoformatted using php-cs-fixer build by the same people who make Symfony.
To add to #4, this would be a major turn away to me, if I were an employer, since it is also very inefficient and hides some issues. There are occasions in PHP where it is necessary (since a built-in function throws warnings instead of exceptions etc), but these are few and far between.
That's not necessary because sessions are signed by default. Someone can read the cookie, and someone can change it, but as soon as it gets changed, the signature and the content no longer match, and flask will reject it.
edit: I checked out your site. One thing I noticed is that the server shows up as Werkzeug/0.11.15 Python/3.4.3
. Am I correct in assuming that you're just running app.run()
in screen after opening up port 8380? Even the documentation says it doesn't scale, so if your business gets big or even a little bit beyond obscurity, it'll be really slow and unresponsive since the flask server doesn't thread or fork. Here's a pretty good guide on deploying it behind nginx.
Correct? Sure. This is basically a recursive implementation done with a stack to avoid true recursion. However, I believe you'll wind up re-checking the same subproblems repeatedly, meaning it's inefficient.
You could memoize it (I gave it a shot in JS here) or use a dynamic programming bottom-up style.
>As an aesthetic the g_
prefix is a bit much IMO. While they're technically "global" think of your module (the python file) as it's own namespace. If something else imports it all of those "global" variables will be wrapped up under that module name.
Hmm, makes sense; as you mention later, encoding type rather than scope info into variable names seems much more useful and worthwhile in a dynamic language.
>You've got a lot of functions but none of them are taking any parameters and relying on global variables. You should probably just have those methods requesting what they need as parameters. That way if it does need to be a global, you can grab it and pass it in to whatever calls it.
Hah, good catch. I guess I started out writing them as procedural scripts and then refactored into functions, so it ended up looking a lot like "assembly" in the sense of "set this register, call that address, ...".
>You might check out the <code>pathlib</code> library as a good object-based abstraction from file paths. I found it incredibly useful for keeping things nice and readable without introducing a bunch of constants and slashes everywhere.
Will do!
No problem! I enjoy helping people out. If you're really serious about coding as a profession, I would recommend reading Clean Code (it's easy to find a free pdf version online). A lot of these concepts I talked about are very clearly defined and explained in this book.
Happy coding!
I took a quick look at 'Clean Code', and it seems quite good. I think the authors put it well Chapter 12, Topic "Minimal Classes and Methods":
>Even concepts as fundamental as elimination of duplication, code expressiveness, and the SRP can be taken too far. In an effort to make our classes and methods small, we might create too many tiny classes and methods. So this rule suggests that we also keep our function and class counts low.
I think splitting your code in to functions that are only called once are fine when you have a super long block of code that is hard to read. But OP's project has lots of functions that are really just one line of real code and are only called once, which doesn't actually make the code that much simpler to read.
> If you only need a certain block of code once, it doesn't really need a method.
This is interesting, I'm reading 'Clean Code' right now and the authors say that each method should do only 1 thing and you should split into sub-methods for readability. Your advice makes sense though, I wonder what the best practice is for this?
Being a student you may be unaware that Access is not well liked in 99 percent of the software development community. And "not well liked" is a euphemism for something else. Looks like you're on the right track with the code, you may want to pick up Effective Java, great book for good practices. And you might want to consider BitBucket or GitHub instead of SourceForge.
A little late, but here are my thoughts. Note that I am being very blunt, because I think putting it nicely would be lying by omission: your code is not good C++. I am guessing you learned C++ from online tutorials or old books. Get yourself a proper C++ book that explains the language properly; it will save you a lot of trouble in the meantime.
Now, as for specific examples:
END_OF_FUNCTION
macro do?destroy
or delete
, chances are you are doing something wrong.All in all, the code is a mess. If you are attached to this project, you can try to refactor things, but I think you should focus on writing a few small, complete applications in modern C++. Focus on writing working, clear, concise code. Good books are Accelerated C++ and C++ Primer (not C++ Primer Plus), by the way.
I know this is harsh, but it is as constructively as I can put it: you need a proper source of learning and a clean slate to work on.
Hi Lerke,
I thought I had enough to keep me going on with this. I tried to incorporate a List into this solution, to have a dedicated ContactBook List that held multiples of Contact, I didn't succeed. I kept going and read through Inheritance and came up with this magical idea that the Contact could Inherit from the Book (not true inheritance as there are no shared properties) but wanted to use it as a test. Truth is I'm all over the place with it, I've uploaded a solution that if you have a moment could you please look at it? http://www.filedropper.com/contactbook (VS2015 as a .zip).
I think what I have is at odds with each other. On the one hand it's inheritance on the other there is the List<Contact> and neither is making much sense at the minute. I looked around the web but I keep finding Struct Array examples, not List Class examples.
Thank you in advance.
I rewrote your code to try to illustrate some things.
This isn't necessarily how I would do it exactly, but I wanted to show you some different patterns.
https://codesandbox.io/s/bmi-calculator-forked-j6sdq?file=/src/App.js:0-3147
So it seems like there are some better alternatives to matplotlib for large datasets, with some interesting discussion on StackOverflow.
Update: Well, this works: http://codepad.org/ESx7oSY5
I have no idea why, I tried doing exactly that (I think) multiple times and it didn't work, now it does.
Shame I didn't document all the failed attempts to see exactly how, but now I know that I should do it.
Very helpful, thank you.
The Counter thing was from this example:
https://www.typescriptlang.org/docs/handbook/interfaces.html#hybrid-types
This works for a reason I do not understand let counter = function (start: number) {} as Counter;
, while when I tried interface X { y : number } let z = 3 as X;
that did not work. What am I missing here?
> It's the Translator and LanguageDetector. I've updated the code to inject the api_key into them.
Ah! you can create GTranslateAPI
class where you put all API calls and response parser methods :)
Take a look: https://repl.it/repls/EsteemedCrookedCgi
EDIT: Probably better to use GTranslateAPI as dependency injection instead of create an instance in the constructor
You should look at mail chimp https://mailchimp.com/ what you are describing can be done on their free plan. Plus you get metrics of open and bounces, function to allow users to unsubscribe and many other features.
The actual code aspects of sending an email to a list of customers and changing the template to insert a customers name is very simple. However successfully and legally using email for marking is more complicated.
Sending email from a dynamic IP on some home users ISP network isn't going to get through even the most basic spam filters.
>> it cannot be accessed by index >> >> ... >> >> SortedSet<T> is usually built on top of a balanced tree structure
>That, however, is news to me... and very good to know. Is the Scala version implemented the same way? Google didn't have a quick answer, and since an explicit TreeSet exists, it's hard to infer.
If you go to the trait definition of mutable.SortedSet and either open up class hierarchy or the 'known subtypes' section, you'll see that TreeSet
is a concrete implementation of SortedSet
trait. :) And there are only two concrete implementations of that trait, another one is BitSet
.
So, everything checks out!
>If you ever find that snippet, let me know.
Sure, I'll just send you a PM then.
> Maybe I wasn't really clear here, because Java also has SortedSet<T> interface.
No, you were clear enough... I had never heard of that interface either. Lol.
> it cannot be accessed by index
> ...
> SortedSet<T> is usually built on top of a balanced tree structure
That, however, is news to me... and very good to know. Is the Scala version implemented the same way? Google didn't have a quick answer, and since an explicit TreeSet exists, it's hard to infer.
> I think I have some really simple XML serializer [...] snippet somewhere around...
If you ever find that snippet, let me know.
> No problem, feel free to PM me. I know a little bit of Scala, so I certainly don't know everything, but I'll answer what I can.
Thanks! Anything you can't answer is simply an opportunity for us both to learn, rather than just me.
> Also, you might have noticed that I don't really know much about Java ecosystem (e.g. frameworks and such) :)
Yeah... me neither, sadly. All of my professional experience is with MUMPS derivatives, so memorizing Java's core framework API was never been very high on my priority list. =/
I figured you might come back and edit later :)
The course requires being enrolled, might be why I didn't see it on a quick search. But the Syllabus is a good run down for the course, and the algorithms involved.
I'm not a Python programmer, but I got an online IDE to run it. OP code runs
Thanks you! Here's some more changes. I didn't rely too heavily on method chaining, I was worried that if one method failed, it would break the chain. Also, this class is accessed by AJAX only, so there was no need to have a dedicated getUrl method. Since I'm not familiar with constructor dependency injection i decided to avoid it for now: https://pastebin.com/qEMmrsN6
This is the updated version: https://pastebin.com/8Lm8vHVS
One thing I'm concerned about is how busy the constructor is. Also, how to handle $_GET when using a constructor.
first thing i'd do is follow pep8: https://www.python.org/dev/peps/pep-0008/
you can use an ide like pycharm (https://www.jetbrains.com/pycharm/) which should highlight pep8 violations for you and some automation with fixing those violations. alternatively, you can find a linter to run.
I plan on revamping it completely since I can clearly see that the code doesn't really "explain itself". I am currently reading Clean Code: A Handbook of Agile Software Craftsmanship and when I finish this book I will start over.
Hi Lerke,
yes this was my first idea. I'd started watching videos and reading this. In the videos I was all the way up to delegates but there was nothing to practice and so I did some data type, notation and type lessons but got a bit frustrated that there were no real world items. I got the idea for the contact book, something that I could build upon. I didn't want to go too far in the videos because you just glaze over without any real practice but I also wanted something that I'd built so that I could then add to them as I'd learned a new part i.e. delegates, inheritance.
> Your main class really shouldn't have anything to do with holding individual contacts, as individual contacts are what makes a Contact Book!>
With this line you cleared up my issue, I did basic UML all those years ago and its all making sense now, the paper and pen method is something I should have done to iron out the issue I had.
I've checked out the MS course and I like the assessments and nature of the course. I'll track down that yellow book too. I'm just after something that gives good examples that you build on rather than throw away.
Once again, so many thanks, you've really been such a help with this, an inspiration and if you didn't know it you are actually a kick ass teacher to boot! Thanks for your help and time!