Drupal is an incredibly flexible and expressive CMS and development framework. As adeveloper, it allows you to express yourself quickly and easily. That being said, being able to do anythingâ can be a little overwhelming.
Switching from .NET to Drupal 7 isn't easy for most people. They take fundamentally differentapproaches to development that aren't called out. There is also a surprising lack of articles and documentation on the subject. Two years ago I made the change to Drupal. I didn't haveanyone to help, so the transition was harsh. Developers not only struggle with the transition, butmore importantly with the ability to adopt best practices. The end result is often unstable, andunmaintainable.
This is the first post in a series highlighting the differences between .NET and Drupal. The goalis to help you as a developer map concepts from .NET to Drupal and give you the foundationyou need to be successful with Drupal. You'll see that Drupal development is actually easy,robust, and a lot of fun.
Drupal is a CMS but it's also a development framework. Where .NET has an API for everything,Drupal has a lean core API, and a large ecosystem of open-source modules to provide extrafunctionality. This is where Drupal's CMS background shines. Drupal has fully completedmodules designed to meet business needs. There is a module for everything: modules forstyling content on a page, displaying social content, and even translation. I cannot stress thispoint enough. There is a rich open source community in your corner backing you up. Moduleskeep you from reinventing the wheel and allow you to dramatically increase your developmentvelocity.
While you have a clear API to follow with .NET or Java, Drupal requires a certain amount oftribal knowledge to build a real site. You need to be able to know which module meets yourneeds. It's overwhelming at first. Here you are struggling to figure out Drupal core and at thesame time, you have to figure out all these modules as well. It takes time, but eventually youstart to get a feel for some of the basic modules to start with. (I recommend checking outLightningâ for a curated list that we use here at Acquia. And posts âon identifyingâ, âsearching,â and evaluatingââ Drupal modules).
In order to understand the chasm between .NET and Drupal it helps to understand thebackground and differences between C# and PHP.
C# is a descendant of C, C++, and Java. As such, C# has been around for a while and has amature object model. PHP only added modern OO capabilities in PHP 5.0 (2005) and late staticbinding in PHP 5.3 (2009). PHP is a relative newcomer to the OO world.
The difference strongly influences code structure and coding practices in Drupal 7. A lot of PHPcode in D7 is largely procedural. Some of the newer PHP code is OO but in D7 that's theexception rather than the rule. This means that functions are not grouped together in small ormedium understandable objects, or even namespaces. Most functions are defined in a globalscope. Procedural code lacks the structure and aesthetic of OO code.
In an object-oriented world, a clear hierarchy of objects guides your development. When you areworking in Java or ASP.NET, that object hierarchy can be reassuring. You can turn to it to tellyou what to do. It is also listed in the API documentation, and you can drill down through it tounderstand what you need to do to effect change.
You can also always look at the object in a debugger to see all the methods and propertiessupported. The lack of object inheritance in procedural code makes it difficult to follow code andunderstand what is happening. In a procedural language you need to simply know the functionsthat are available to you. Since most functions are defined in global scope, they can beoverwhelming!
The other major difference is that C# is a strongly typed language and PHP is a loosely typedlanguage. In strongly typed languages, such as C#, variables are declared with a type. Inloosely typed languages, no type is required.
C#string myVar = 'This is a strongly typed declaration';
PHP$my_var = 'This is a loosely typed declaration';
One has a type and one doesn't. So what's the big deal? By looking at a variable declaration inC# you immediately know that it is storing a string. On the other hand, in PHP, you can onlyinfer based on the right side of the declaration statement.
Here is a great example of the confusion this can lead to:
$my_var = node_load(123456);
What is the type of âmy_varâ? Without knowing what ânode_loadâ returns you have no idea. â âThisis represents a huge barrier to reading and understanding PHP code. I cannot stress thisenough. Loose typing along with the fact that functions are defined in global scope meansreading PHP code requires a much broader understanding than C#.
The combination of procedural code, lack of an object model, and loosely typing means thatDrupal/PHP has to get creative when passing around bundles of information. It does this bycreating infinitely nested âdynamic arraysâ. Theses are incredibly powerful, flexible, and are coreto Drupal's ability to be customized to meet almost any need.
That being said, Drupal arrays can be hard to understand and follow. They are also largelyundocumented and undocumentable. For a more in depth explanation see John Alban's post onDrupal 7 and the Arrays of Doomâ.
So how do you work with these arrays? Most developers will either print them using the âDevelmodule's dpmâ or by using a PHP debug tool, such as âPHPStormâ. I'll discuss both approachesmore in depth in a later post. By poking around inside these structures you start to understandwhat's going on and how to enact changes!
In Drupal, the distinction between code and config can be ambiguous. Since .NET is aframework not a CMS, there a clear line of demarcation between what is code and what isconfig stored in a database. In general items stored in the database represent content/usersettings/config.
Drupal, on the other hand, is a CMS, one that is extremely customizable via the user interface.We call thisâ site-building. âIn Drupal, you can build a new content type just as easily as you cancreate a new article. This flexibility and configurability are one of Drupal's strengths. However,from a developer's point of view, this makes things confusing. When do you need to write code?When do you need to do things via the GUI? The line between code and config is extremelyblurry and often debated among Drupalistas. (We'll cover this more in a later segment.)
No doubt, Drupal comes with its fair share of challenges, a few of which we just talked about.But those challenges are not insurmountable. At the end of the day, the things that can makeDrupal tricky also contribute to its flexibility and power. These attributes have positioned Drupalas a CMS leader. I hope that mapping concepts from .NET to Drupal in this blog series will helpmake the transition smoother and easier for you.
In future blog posts, I'll go into depth on some of the more granular elements of Drupal, such asworking with hooks, modules, and Drupal core. Stay tuned.
If this content did not answer your questions, try searching or contacting our support team for further assistance.
Sun Mar 31 2019 01:07:39 GMT+0000 (Coordinated Universal Time)