Ok, I'm not trying to start a discussion on Camelcase vs Underscore here, it doesn't matter what you pick, just stick to your choice.
Rather, what I would like peoples opinion on, is how strict and committed you should be in your choice when importing third party libraries.
Especially in PHP there is a HUGE variety of coding styles, to the point where it's just damn near impossible to maintain one specific style throughout your codebase when you use third party libraries.
So what do you guys do? Modify those libraries to suit your conventions, write some sort of interpreting layer so that when you use those libraries the usage of them still follows your conventions? Do you just say "to hell with it" and mix it all together? Or is there some other ingenious solution that I haven't thought of (apart from simply not using libraries that don't follow your convention)?
In essence what I'm asking is; how do you manage to maintain a clean and consistent coding style when using third party libraries? Can it be done?
I say "to hell with it" and mix it all together. It can be somewhat annoying to have the mixed styles, but I don't think it's worth it to do a bunch of work to avoid this.
Related
My colleagues use a 4-spaces indentation style on a JavaScript project. I personnaly prefer a 2-spaces indentation for JS.
Should I bother them with that?
In general I think it is a good habit to discuss and finalize a common code style guideline in the project team. Like that, you are able to work more efficiently in the team and you can avoid merging troubles caused by auto-formatter when using version control systems as Git.
Also for your specific case I would recommend to discuss it and come to an agreement for a common guideline. However, most version control systems are able to ignore the indents when comparing files, so it would not have a that big impact there.
Is Dojo's load-as-you-need it structure actually a performance improvement? For me, at least?
My company's website is going to switch to IBM Websphere, which primarily uses Dojo. My company's very concerned with page performance, mostly in terms of "seconds to page load". As a result of that, the directive we've been given is "minimize hits to the server", so with our current website we aggregate all our .js files before the promotion to production.
But that directive is basically becoming Law, now, so if I were to argue against it, I would need a very good rationale for it. I've been unable to find anything in favor of the load-as-you-go method except "it's a good idea" and "loads only when you need it" (the latter is really only based on the former, as far as I can tell).
And then, if I were to flatten everything out into a single file, I wouldn't be able to use dojo.require() statements at all, would I? (the idea being, if I could have the development side split by module to make the organization more rational, but then have the production version a single file, but then dojo.require() would no longer make sense there, and then I have an increasingly complex situation where I would need the build to do some invasive things to the javascript to package for production.)
Please resist the "it depends" answer. The best practices docs I've seen (Yahoo, Google, etc) pretty much just say "reduce page loads" and don't have much "it depends" about it. But Dojo's framework seems so definitive about its approach, I'm wondering if there's a more persuasive argument for it.
Dojo actually combines the two approaches. In development mode, you have many files that use define (dojo.require is obsolete) to load other modules dynamically. This is very good for abstraction and development.
Then there is "production mode", where you compile all those small files into one or more (aka. layers) minified Javascript files with the dojo build system. This reduces hits to the server while still maintaining all the modularity. With the layer approach, application data that is needed later will automatically be loaded from a separate file.
See:
http://dojotoolkit.org/blog/learn-more-about-amd
http://dojotoolkit.org/reference-guide/1.7/build/
i am pretty new to CI. been looking at few template libraries but found either they have much more than I need or not enough.
so i started to build my own. is there anything i should keep in mind? in terms of security? caching? etc etc
thank you
A template library is pretty simple to create and unless you have a need for all the stuff that one of the many available have I would just roll your own. With that said I tend to use the one by Phil the most as it matches the closest with the way I do things.
I am at a company that does not understand the concept of using frameworks and the benefits of them. I have tried to explain that it provides structure and organization but the people I am trying to explain to are still a little fuzzy about it. In your opinion, what is the best way to describe a framework in the most simplest terms and how it could overall benefit a company to transition their code from procedural and spaghetti code to a nice organized framework?
Thank you for your time.
I guess the best explanation I can think of for using a framework are to standardize your design process and save yourself a lot of effort as your code-base grows. Not to mention that a lot of work can be taken care of for you by the framework (which could save hours of coding). A framework can give you all the parts you need to build your application, you just have to assemble them.
The best reasons I can think of for using a framework are:
Code reuse -- If you try and follow the design of the framework you can save yourself a lot of coding time. However, some frameworks do require a time investment to master.
Encapsulation -- You can change the underlying implementation of different parts of the framework in a way that doesn't require a lot of code rewriting.
Extendability -- You can extend the code of the framework to add features you need and if you are careful about your design, you can reuse these features too.
I'm sure there are many other good reasons, but I'm sleepy.
EDIT: A good example of the benefits of a framework can be replacing the database adapter with another ie. switching from mysql to postgresql. This could be awful with functional programming but a framework could make this transition very easy.
Your coworkers most likely already use libraries, which one could define as code that exists outside of your project, and is meant to used in many projects.
A framework is like a library, but usually has other featues, such as
It might enforce changes to your code. For example, you wouldn't replace one method of your WebForms project with a call to the ASP.NET MVC framework - the entire project would be written differently to conform to the framework.
It might restrict the universe of applications that you can write. For example, you might be using a CRUD generating framework that lets you make data entry applications, but wouldn't let you make a video editing application.
However, a framework will usually give you a lot of value in return.
Let them do as they like ,first.
then pick up their shortcomings and
finally generalise your framework to avoid procedural code.
I'm going to concentrate on only a part of the question:
In your opinion, what is the best way to describe a framework in the most simplest terms
Framework == Library + Inversion of Control
What are some of the best practices for OOD with Ruby? Mainly, how should files and code be organized?
I have a project that uses several classes and files and I am just wondering how it should all be organized, grouped and included.
It sounds like you're asking which pieces go in which files.
Is your project a Web application? In that case you would most likely use the system of organization imposed by your framework (Rails, Merb, Sinatra, etc.)
Other kinds of projects also have their own typical structure that you can just follow. E.g. gems are usually set up in a certain way.
If it's a console app, there's no strict rule. Usually people put no more than one class or module in a file. You could have one main file that requires all the others.
Standard OOD concepts apply to ruby. For specifics, maybe this guide will be helpful:
http://www.rubyist.net/~slagell/ruby/oothinking.html